xonya
xonya

Reputation: 2484

List ClusterServiceVersions using K8S Go client

I'm trying to use the K8S Go client to list the ClusterServiceVersions. It could be enough to have the raw response body.

I've tried this:

data, err := clientset.RESTClient().Get().Namespace(namespace).
    Resource("ClusterServiceVersions").
    DoRaw(context.TODO())

if err != nil {
    panic(err.Error())
}

fmt.Printf("%v", string(data))

But it returns the following error:

panic: the server could not find the requested resource (get ClusterServiceVersions.meta.k8s.io)

How do I specify to use the operators.coreos.com group?

Looking at some existing code I've also tried to add

VersionedParams(&v1.ListOptions{}, scheme.ParameterCodec)

But it result in this other error:

panic: v1.ListOptions is not suitable for converting to "meta.k8s.io/v1" in scheme "pkg/runtime/scheme.go:100"

Upvotes: 3

Views: 764

Answers (1)

xonya
xonya

Reputation: 2484

It is possible to do a raw request using the AbsPath() method.

path := fmt.Sprintf("/apis/operators.coreos.com/v1alpha1/namespaces/%s/clusterserviceversions", namespace)

data, err := clientset.RESTClient().Get().
    AbsPath(path).
    DoRaw(ctx)

Also notice that if you want to define clientset using the interface (kubernetes.Interface) instead of the concrete type (*kubernetes.Clientset) the method clientset.RESTClient() is not directly accessible, but you can use the following one:

clientset.Discovery().RESTClient()

Upvotes: 2

Related Questions