I need to write a k8s controller using kubebuilder that watches objects of all kinds in a api group. It should also support dynamic kinds in the api group. That is if a new CRD is installed that belongs to the same api group and an instance of it is created then the controller should pick it up.
Is this possible at all? What are some of the other alternatives? e.g. hard-code the kinds (or take it from a config) and use the watches function to monitor the resources?
Thanks to some of the ideas from comments, I was able to make it work like the below. The code is part of the
SetupWithManagerfunction. The idea is to listen for CRDs and then dynamically create controllers based onGVKI also filtered the CRDs using predicate function (not part of snippet above)
and then need a reconciler function like below
The key really is to set the
GVKon unstructured types. Understand this might be not recommended, becauseDo one thing and do it good.but it works for my specific use case.