Get namespace quotas using k8s client-go

8/20/2019

I am looking for a way to get resource quotas for the namespace using client-go, similar to kubectl describe ns my-namespace-name.

I have tried ns, err := k8client.CoreV1().Namespaces().Get("my-namespace-name", metav1.GetOptions{}) but it does not give quota info.

Also tried ns, err := k8client.CoreV1().ResourceQuotas("my-namespace-name").Get("name", metav1.GetOptions{}) but I can not figure out what to put as name parameter in .Get(). Tried namespace name, tried several resource types from https://kubernetes.io/docs/reference/kubectl/overview/#resource-types but no luck with errors like resourcequotas "namespaces" not found or resourcequotas "limits.cpu" not found

Tried ns, err := k8client.CoreV1().ResourceQuotas("my-namespace-name").List(metav1.ListOptions{}) as well but it returned no result.

Any ideas on how to get it will be much appreciated!

-- JLevconoks
client-go
kubernetes
kubernetes-go-client

1 Answer

8/22/2019

Ok, after some debugging and going through kubernetes and kubectl code, the way to get it is: ns, err := k8client.CoreV1().ResourceQuotas("my-namespace-name").List(metav1.ListOptions{})

Not sure why it did not work for me first time I have tried, might have made a typo in namespace name.

-- JLevconoks
Source: StackOverflow