Unable to get K8S resources in kubebuilder's client.Client for unit test
Posting this in case others find it useful. If you want to access other K8S resources, you would need to use the standard clientSet
object from Kubernetes' client-go. For e.g. if you want to confirm that a specific namespace called targetNamespace
exists:
mgr, _ := manager.New(cfg, manager.Options{})generatedClient := kubernetes.NewForConfigOrDie(mgr.GetConfig())nsFound := falsenamespaces := generatedClient.CoreV1().Namespaces()namespaceList, _ := namespaces.List(metav1.ListOptions{})for _, ns := range namespaceList.Items { if ns.Name == targetNamespace { nsFound = true break }}g.Expect(nsFound).To(gomega.BeTrue())log.Printf("Namespace %s verified", targetNamespace)