Skip to content

Commit 4ef7f3b

Browse files
Fix that Whisker controller was not watching ClusterInformations (#3924)
1 parent 42abccf commit 4ef7f3b

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

pkg/controller/goldmane/controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
6161
return fmt.Errorf("failed to create %s: %w", controllerName, err)
6262
}
6363

64-
err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{})
65-
if err != nil {
64+
if err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}); err != nil {
6665
return fmt.Errorf("%s failed to watch primary resource: %w", controllerName, err)
6766
}
6867

@@ -81,8 +80,7 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
8180
return fmt.Errorf("failed to add watch for config map %s/%s: %w", common.OperatorNamespace(), certificatemanagement.TrustedCertConfigMapName, err)
8281
}
8382

84-
err = c.WatchObject(&operatorv1.ManagementClusterConnection{}, &handler.EnqueueRequestForObject{})
85-
if err != nil {
83+
if err = c.WatchObject(&operatorv1.ManagementClusterConnection{}, &handler.EnqueueRequestForObject{}); err != nil {
8684
return fmt.Errorf("%s failed to watch management cluster connection resource: %w", controllerName, err)
8785
}
8886

@@ -102,6 +100,12 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
102100
return fmt.Errorf("goldmane-controller failed to watch Tigerastatus: %w", err)
103101
}
104102

103+
// Perform periodic reconciliation. This acts as a backstop to catch reconcile issues,
104+
// and also makes sure we spot when things change that might not trigger a reconciliation.
105+
if err = utils.AddPeriodicReconcile(c, utils.PeriodicReconcileTime, &handler.EnqueueRequestForObject{}); err != nil {
106+
return fmt.Errorf("goldmane-controller failed to create periodic reconcile watch: %w", err)
107+
}
108+
105109
return nil
106110
}
107111

pkg/controller/whisker/controller.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
6262
return fmt.Errorf("failed to create %s: %w", controllerName, err)
6363
}
6464

65-
err = c.WatchObject(&operatorv1.Whisker{}, &handler.EnqueueRequestForObject{})
66-
if err != nil {
65+
if err = c.WatchObject(&operatorv1.Whisker{}, &handler.EnqueueRequestForObject{}); err != nil {
6766
return fmt.Errorf("%s failed to watch primary resource: %w", controllerName, err)
6867
}
6968

70-
err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{})
71-
if err != nil {
69+
if err = c.WatchObject(&operatorv1.Goldmane{}, &handler.EnqueueRequestForObject{}); err != nil {
7270
return fmt.Errorf("%s failed to watch for goldmane resource: %w", controllerName, err)
7371
}
7472

@@ -102,6 +100,16 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
102100
return fmt.Errorf("whisker-controller failed to watch Tigerastatus: %w", err)
103101
}
104102

103+
if err = c.WatchObject(&crdv1.ClusterInformation{}, &handler.EnqueueRequestForObject{}); err != nil {
104+
return fmt.Errorf("whisker-controller failed to watch ClusterInformation")
105+
}
106+
107+
// Perform periodic reconciliation. This acts as a backstop to catch reconcile issues,
108+
// and also makes sure we spot when things change that might not trigger a reconciliation.
109+
if err = utils.AddPeriodicReconcile(c, utils.PeriodicReconcileTime, &handler.EnqueueRequestForObject{}); err != nil {
110+
return fmt.Errorf("whisker-controller failed to create periodic reconcile watch: %w", err)
111+
}
112+
105113
return nil
106114
}
107115

@@ -127,7 +135,6 @@ func newReconciler(
127135
// blank assignment to verify that ReconcileConnection implements reconcile.Reconciler
128136
var _ reconcile.Reconciler = &Reconciler{}
129137

130-
// Reconciler reconciles a ManagementClusterConnection object
131138
type Reconciler struct {
132139
cli client.Client
133140
scheme *runtime.Scheme
@@ -227,7 +234,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
227234
clusterInfo := &crdv1.ClusterInformation{}
228235
err = r.cli.Get(ctx, utils.DefaultInstanceKey, clusterInfo)
229236
if err != nil {
230-
reqLogger.Info("Unable to retrieve cluster context to Whisker. Proceeding without adding cluster context to Whisker.", err)
237+
reqLogger.Info("Unable to retrieve ClusterInformation", "error", err)
231238
} else {
232239
cfg.CalicoVersion = clusterInfo.Spec.CalicoVersion
233240
cfg.ClusterType = clusterInfo.Spec.ClusterType

0 commit comments

Comments
 (0)