Skip to content

Commit

Permalink
Add input validations for controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Oct 23, 2024
1 parent c3ae478 commit 9c90a00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}).
Expand Down
7 changes: 4 additions & 3 deletions internal/controllers/machinehealthcheck/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 9c90a00

Please sign in to comment.