How to watch external resources in kubernetes controller with Kubebuilder

112 Views Asked by At

I am trying to watch an external CR (Tenant) in a Kubernetes controller. I have setup a reconciler with Kubebuilder. I am not sure how to make the controllermanager watching the external CR. I also read this post (How to watch for external custom resource changes in kubebuilder without importing the external type

With Kubebuilder I have created a Reconciler and I am trying to let it Watch for the external CR.

// SetupWithManager sets up the controller with the Manager.
func (r *TenantReconciler) SetupWithManager(mgr ctrl.Manager) error {

    return ctrl.NewControllerManagedBy(mgr).
        // Uncomment the following line adding a pointer to an instance of the controlled resource as an argument
        For(&externalResource). ==> how can I supply an external CR?
        Complete(r)
}

I also added the dynamic client to the controller to be able to discover any resource and created a GroupVersionKind for this external resource.

But still it is not considered as a client.Object.

type TenantReconciler struct {
    client.Client
    Scheme        *runtime.Scheme
    DynamicClient dynamic.Interface
}
0

There are 0 best solutions below