encoding is not allowed for this codec: *versioning.codec

3/4/2019

I have made a kubernetes operator using this framework https://github.com/operator-framework/operator-sdk in which I have a small custom resource definition defined and a clientset generated.

I create a client for this custom resource doing:

imports are (
    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/rest"
)

config, err := rest.InClusterConfig()
kubernetesClientset := kubernetes.NewForConfig(config)
// my generated CR clientset
v1alpha1.New(kubernetesClientset.RESTClient())

So I simply use the config kubernetes gives to pods and created a default k8s REST clientset and use that in my custom resource's clientset (Is that even a good practice?).

However when I try to use my custom resource clientset and try to create an instance of the custom resource the client errors with encoding is not allowed for this codec: *versioning.codec (I guess it comes from here https://github.com/kubernetes/apimachinery/blob/master/pkg/runtime/codec.go#L104).

What does that exactly mean? I thought the generated client is aware of the custom resource?

Thanks for help...

-- Robin Brämer
client
kubernetes
kubernetes-apiserver
kubernetes-custom-resources

1 Answer

3/27/2019

I had the same problem due to restclient misconfiguration. Have a look how restclient is created and configured in the example here.

-- Artem
Source: StackOverflow