Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List ClusterServiceVersions using K8S Go client

Tags:

go

kubernetes

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"
like image 286
xonya Avatar asked Sep 10 '26 04:09

xonya


1 Answers

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()
like image 67
xonya Avatar answered Sep 12 '26 04:09

xonya