K8s Test - NewSimpleClientset for schemaless custom resource

182 Views Asked by At

I have a method which uses client-go's dynamic.Interface to dynamically fetch a schemaless custom resource called IstioOperator.

iops, err := client.Dynamic().Resource(constants.IstioOperatorGVR).
    Namespace(brConfig.IstioNamespace).
    List(ctx, metav1.ListOptions{})

I want to unit test this function. For that I'll have to mock the client so that it returns the provided CR. I am trying to mock it using NewSimpleClientset from k8s.io/client-go/kubernetes/fake package. When I pass the runtime object while initializing NewSimpleClientset, it panics with the following error:

panic: no kind is registered for the type v1alpha1.IstioOperator in scheme "pkg/runtime/scheme.go:100"

So how to register the kind v1alpha1.IstioOperator in the mentioned scheme for unit testing?

0

There are 0 best solutions below