diff --git a/internal/controllers/cluster/cluster_controller.go b/internal/controllers/cluster/cluster_controller.go index 17a646bcfc32..78c5dc5d90e5 100644 --- a/internal/controllers/cluster/cluster_controller.go +++ b/internal/controllers/cluster/cluster_controller.go @@ -87,6 +87,10 @@ type Reconciler struct { } func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { + if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil || r.RemoteConnectionGracePeriod == time.Duration(0) { + return errors.New("Client, APIReader and ClusterCache must not be nil and RemoteConnectionGracePeriod must not be 0") + } + predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster") c, err := ctrl.NewControllerManagedBy(mgr). For(&clusterv1.Cluster{}). diff --git a/internal/controllers/machinehealthcheck/suite_test.go b/internal/controllers/machinehealthcheck/suite_test.go index 69dc6beea760..85d4ef9b8bc4 100644 --- a/internal/controllers/machinehealthcheck/suite_test.go +++ b/internal/controllers/machinehealthcheck/suite_test.go @@ -93,9 +93,10 @@ func TestMain(m *testing.M) { SetConnectionCreationRetryInterval(2 * time.Second) if err := (&clustercontroller.Reconciler{ - Client: mgr.GetClient(), - APIReader: mgr.GetClient(), - ClusterCache: clusterCache, + Client: mgr.GetClient(), + APIReader: mgr.GetClient(), + ClusterCache: clusterCache, + RemoteConnectionGracePeriod: 50 * time.Second, }).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil { panic(fmt.Sprintf("Failed to start ClusterReconciler: %v", err)) }