I have a controller that is managing the lifecycle of other CRDs. Given the following code:
err = c.Watch(&source.Kind{Type: &v1beta1.CustomResourceDefinition{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &maestrov1alpha1.Framework{},
})
kubebuilder fails to register controllers for the manager with the following error:
{"level":"error","ts":1542781339.090334,"logger":"entrypoint","caller":"manager/main.go:63","msg":"unable to register controllers to the manager","error":"no kind is registered for the type v1beta1.CustomResourceDefinition","stacktrace":"github.com/kubernetes-sigs/kubebuilder-maestro/vendor/github.com/go-logr/zapr.(*zapLogger).Error\n\t/Users/gerred/go/src/github.com/kubernetes-sigs/kubebuilder-maestro/vendor/github.com/go-logr/zapr/zapr.go:128\nmain.main\n\t/Users/gerred/go/src/github.com/kubernetes-sigs/kubebuilder-maestro/cmd/manager/main.go:63\nruntime.main\n\t/usr/local/Cellar/go/1.11.2/libexec/src/runtime/proc.go:201"}
I tried updating controller-runtime to 0.1.7 and controller-tools to 0.1.6 by hand, this didn't seem to help. The stack trace was a little unhelpful. Any pointers in tracking this down would be greatly appreciated.
FWIW, I also could not use ReconcileFramework's client. I get the same error (albeit in a different way). I had to pull in apiextensionsclient by hand to use in the Reconcile step.
On second thought, it may not be preferable that a CRD's lifecycle is automatically managed as well, so maybe this behavior is a good warning to the path I'm taking.
^ Also getting bit by PropagationPolicy here. Going to close, I think I can solve this from an implementation side in a cleaner way with finalizers.
For posterity: this is generally caused by not having your scheme set up correctly. All types you want to use must be added to your scheme. The default Kubernetes scheme (which is used in CR if none is specified) contains most of the main Kubernetes types, but does not contain CRDs.
So, for example, assuming you want to reference Kubernetes types, CRDs, and some of your own types:
package main
import (
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
kscheme "k8s.io/client-go/kubernetes/scheme"
myapi "my.api/group/version"
"k8s.io/apimachinery/pkg/runtime"
controllers "sigs.k8s.io/controller-runtime"
)
var (
scheme = runtime.NewScheme()
)
func init() {
kscheme.AddToScheme(scheme)
extapi.AddToScheme(scheme)
myapi.AddToScheme(scheme)
}
func main() {
// ...
mgr := controllers.NewManager(config, manager.Options{Scheme: scheme})
// set up your controllers, etc
}
@DirectXMan12 hugs! thank you so much!!!
Most helpful comment
For posterity: this is generally caused by not having your scheme set up correctly. All types you want to use must be added to your scheme. The default Kubernetes scheme (which is used in CR if none is specified) contains most of the main Kubernetes types, but does not contain CRDs.
So, for example, assuming you want to reference Kubernetes types, CRDs, and some of your own types: