If I want to list namespaces on the cluster using client-go I can use a simple command to do this:
clientset.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
And what would the equivalent of the kubectl get crd
command look like?
Is this even possible to do?
I tried to find a solution, but most of the answers I found answered how to query a specific crd, rather than get a list of them.
CodePudding user response:
ApiextensionsV1beta1 API is part of the apiextensions-apiserver library, not the kubernetes library.To access the ApiextensionsV1beta1 API, you will need to import the apiextensions-apiserver library, as follows:
import (
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
)
CodePudding user response:
clientset.ApiextensionsV1beta1().CustomResourceDefinitions().List(context.TODO(), metav1.ListOptions{})
This API returns a list of CustomResourceDefinitions objects.