How do I use openshift/client-go with Kubernetes fake unit test?

10/7/2019

The following code works in an OKD cluster but fails when I try to run it in a Kubernetes fake unit test envir (i.e. using k8s.io/client-go/dynamic/fake) :

routev1 "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
...
routeV1Client, err = routev1.NewForConfig(cfg)
route, _ := routeV1Client.Routes(getkAppNavNamespace()).Get(KappnavUIService, apismetav1.GetOptions{})

Does anyone know how to make this work? The error I get is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1af3132]

goroutine 16 [running]:
github.com/kappnav/controller/vendor/github.com/openshift/client-go/route/clientset/versioned/typed/route/v1.(*routes).Get(0xc00000e7c0, 0x1e018a0, 0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2987bd7, ...)
    /Users/paul/gokappnav/src/github.com/kappnav/controller/vendor/github.com/openshift/client-go/route/clientset/versioned/typed/route/v1/route.go:49 +0xa2
github.com/kappnav/controller.getKappnavWebConsoleExtensionURLs()
    /Users/paul/gokappnav/src/github.com/kappnav/controller/kappnav_handler.go:270 +0x16b

Update: The error above is mine - didn't set routeV1Client correctly. Not seeing a fake version of openshift/client-go/route though. There does seem to be one for openshift/client-go/apps. I suspect I may need to use the generic client if I really want to use the fake unit test envir.

Paul

-- Paul Bennett
go
kubernetes
openshift
unit-testing

0 Answers