goclient-gokubernetes-go-client

The equivalent of "kubectl get crds" in golang


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.


Solution

  • 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"
    )