diff --git a/pkg/controller/goldmane/controller.go b/pkg/controller/goldmane/controller.go index b68b370d39..97b96e8fc3 100644 --- a/pkg/controller/goldmane/controller.go +++ b/pkg/controller/goldmane/controller.go @@ -61,8 +61,7 @@ func Add(mgr manager.Manager, opts options.AddOptions) error { return fmt.Errorf("failed to create %s: %w", controllerName, err) } - err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}) - if err != nil { + if err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}); err != nil { return fmt.Errorf("%s failed to watch primary resource: %w", controllerName, err) } @@ -81,8 +80,7 @@ func Add(mgr manager.Manager, opts options.AddOptions) error { return fmt.Errorf("failed to add watch for config map %s/%s: %w", common.OperatorNamespace(), certificatemanagement.TrustedCertConfigMapName, err) } - err = c.WatchObject(&operatorv1.ManagementClusterConnection{}, &handler.EnqueueRequestForObject{}) - if err != nil { + if err = c.WatchObject(&operatorv1.ManagementClusterConnection{}, &handler.EnqueueRequestForObject{}); err != nil { return fmt.Errorf("%s failed to watch management cluster connection resource: %w", controllerName, err) } @@ -102,6 +100,12 @@ func Add(mgr manager.Manager, opts options.AddOptions) error { return fmt.Errorf("goldmane-controller failed to watch Tigerastatus: %w", err) } + // Perform periodic reconciliation. This acts as a backstop to catch reconcile issues, + // and also makes sure we spot when things change that might not trigger a reconciliation. + if err = utils.AddPeriodicReconcile(c, utils.PeriodicReconcileTime, &handler.EnqueueRequestForObject{}); err != nil { + return fmt.Errorf("goldmane-controller failed to create periodic reconcile watch: %w", err) + } + return nil } diff --git a/pkg/controller/whisker/controller.go b/pkg/controller/whisker/controller.go index 412ac1a35a..0854a5d6c5 100644 --- a/pkg/controller/whisker/controller.go +++ b/pkg/controller/whisker/controller.go @@ -62,13 +62,11 @@ func Add(mgr manager.Manager, opts options.AddOptions) error { return fmt.Errorf("failed to create %s: %w", controllerName, err) } - err = c.WatchObject(&operatorv1.Whisker{}, &handler.EnqueueRequestForObject{}) - if err != nil { + if err = c.WatchObject(&operatorv1.Whisker{}, &handler.EnqueueRequestForObject{}); err != nil { return fmt.Errorf("%s failed to watch primary resource: %w", controllerName, err) } - err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}) - if err != nil { + if err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}); err != nil { return fmt.Errorf("%s failed to watch for goldmane resource: %w", controllerName, err) } @@ -102,6 +100,16 @@ func Add(mgr manager.Manager, opts options.AddOptions) error { return fmt.Errorf("whisker-controller failed to watch Tigerastatus: %w", err) } + if err = c.WatchObject(&crdv1.ClusterInformation{}, &handler.EnqueueRequestForObject{}); err != nil { + return fmt.Errorf("whisker-controller failed to watch ClusterInformation") + } + + // Perform periodic reconciliation. This acts as a backstop to catch reconcile issues, + // and also makes sure we spot when things change that might not trigger a reconciliation. + if err = utils.AddPeriodicReconcile(c, utils.PeriodicReconcileTime, &handler.EnqueueRequestForObject{}); err != nil { + return fmt.Errorf("whisker-controller failed to create periodic reconcile watch: %w", err) + } + return nil } @@ -127,7 +135,6 @@ func newReconciler( // blank assignment to verify that ReconcileConnection implements reconcile.Reconciler var _ reconcile.Reconciler = &Reconciler{} -// Reconciler reconciles a ManagementClusterConnection object type Reconciler struct { cli client.Client scheme *runtime.Scheme @@ -227,7 +234,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( clusterInfo := &crdv1.ClusterInformation{} err = r.cli.Get(ctx, utils.DefaultInstanceKey, clusterInfo) if err != nil { - reqLogger.Info("Unable to retrieve cluster context to Whisker. Proceeding without adding cluster context to Whisker.", err) + reqLogger.Info("Unable to retrieve ClusterInformation", "error", err) } else { cfg.CalicoVersion = clusterInfo.Spec.CalicoVersion cfg.ClusterType = clusterInfo.Spec.ClusterType