Skip to content

Commit e5cbc4a

Browse files
authored
🌱 Add input validations for controllers (#11327)
* Add input validations for controllers * Fix test cases after input validation * Update DockerMachinePoolReconciler to remove unused Scheme
1 parent 0000f09 commit e5cbc4a

29 files changed

+109
-26
lines changed

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ type Scope struct {
103103

104104
// SetupWithManager sets up the reconciler with the Manager.
105105
func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
106+
if r.Client == nil || r.SecretCachingClient == nil || r.ClusterCache == nil || r.TokenTTL == time.Duration(0) {
107+
return errors.New("Client, SecretCachingClient and ClusterCache must not be nil and TokenTTL must not be 0")
108+
}
109+
106110
if r.KubeadmInitLock == nil {
107111
r.KubeadmInitLock = locking.NewControlPlaneInitMutex(mgr.GetClient())
108112
}

exp/addons/internal/controllers/clusterresourceset_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ type ClusterResourceSetReconciler struct {
7070
}
7171

7272
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
73+
if r.Client == nil || r.ClusterCache == nil {
74+
return errors.New("Client and ClusterCache must not be nil")
75+
}
76+
7377
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterresourceset")
7478
err := ctrl.NewControllerManagedBy(mgr).
7579
For(&addonsv1.ClusterResourceSet{}).

exp/addons/internal/controllers/clusterresourcesetbinding_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ type ClusterResourceSetBindingReconciler struct {
4848
}
4949

5050
func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
51+
if r.Client == nil {
52+
return errors.New("Client must not be nil")
53+
}
54+
5155
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterresourcesetbinding")
5256
err := ctrl.NewControllerManagedBy(mgr).
5357
For(&addonsv1.ClusterResourceSetBinding{}).

exp/internal/controllers/machinepool_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ type scope struct {
100100
}
101101

102102
func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
103+
if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil {
104+
return errors.New("Client, APIReader and ClusterCache must not be nil")
105+
}
106+
103107
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machinepool")
104108
clusterToMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &expv1.MachinePoolList{}, mgr.GetScheme())
105109
if err != nil {

exp/internal/controllers/suite_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestMain(m *testing.M) {
6868

6969
if err := (&MachinePoolReconciler{
7070
Client: mgr.GetClient(),
71+
APIReader: mgr.GetAPIReader(),
7172
ClusterCache: clusterCache,
7273
recorder: mgr.GetEventRecorderFor("machinepool-controller"),
7374
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {

exp/runtime/internal/controllers/extensionconfig_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ type Reconciler struct {
6363
}
6464

6565
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
66+
if r.Client == nil || r.APIReader == nil || r.RuntimeClient == nil {
67+
return errors.New("Client, APIReader and RuntimeClient must not be nil")
68+
}
69+
6670
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "extensionconfig")
6771
err := ctrl.NewControllerManagedBy(mgr).
6872
For(&runtimev1.ExtensionConfig{}).

internal/controllers/cluster/cluster_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type Reconciler struct {
8787
}
8888

8989
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
90+
if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil || r.RemoteConnectionGracePeriod == time.Duration(0) {
91+
return errors.New("Client, APIReader and ClusterCache must not be nil and RemoteConnectionGracePeriod must not be 0")
92+
}
93+
9094
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster")
9195
c, err := ctrl.NewControllerManagedBy(mgr).
9296
For(&clusterv1.Cluster{}).

internal/controllers/cluster/suite_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func TestMain(m *testing.M) {
9898
panic(fmt.Sprintf("Failed to start ClusterReconciler: %v", err))
9999
}
100100
if err := (&machinecontroller.Reconciler{
101-
Client: mgr.GetClient(),
102-
APIReader: mgr.GetAPIReader(),
103-
ClusterCache: clusterCache,
101+
Client: mgr.GetClient(),
102+
APIReader: mgr.GetAPIReader(),
103+
ClusterCache: clusterCache,
104+
RemoteConditionsGracePeriod: 5 * time.Minute,
104105
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
105106
panic(fmt.Sprintf("Failed to start MachineReconciler: %v", err))
106107
}

internal/controllers/clusterclass/clusterclass_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ type Reconciler struct {
7171
}
7272

7373
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
74+
if r.Client == nil || r.RuntimeClient == nil {
75+
return errors.New("Client and RuntimeClient must not be nil")
76+
}
77+
7478
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterclass")
7579
err := ctrl.NewControllerManagedBy(mgr).
7680
For(&clusterv1.ClusterClass{}).

internal/controllers/clusterclass/suite_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3939
"sigs.k8s.io/cluster-api/api/v1beta1/index"
4040
"sigs.k8s.io/cluster-api/feature"
41+
fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake"
4142
"sigs.k8s.io/cluster-api/internal/test/envtest"
4243
)
4344

@@ -63,7 +64,8 @@ func TestMain(m *testing.M) {
6364
}
6465
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
6566
if err := (&Reconciler{
66-
Client: mgr.GetClient(),
67+
Client: mgr.GetClient(),
68+
RuntimeClient: fakeruntimeclient.NewRuntimeClientBuilder().Build(),
6769
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 5}); err != nil {
6870
panic(fmt.Sprintf("unable to create clusterclass reconciler: %v", err))
6971
}

internal/controllers/machine/machine_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ type Reconciler struct {
112112
}
113113

114114
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
115+
if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil || r.RemoteConditionsGracePeriod == time.Duration(0) {
116+
return errors.New("Client, APIReader and ClusterCache must not be nil and RemoteConditionsGracePeriod must not be 0")
117+
}
118+
115119
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machine")
116120
clusterToMachines, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineList{}, mgr.GetScheme())
117121
if err != nil {

internal/controllers/machine/suite_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ func TestMain(m *testing.M) {
9494
SetConnectionCreationRetryInterval(2 * time.Second)
9595

9696
if err := (&Reconciler{
97-
Client: mgr.GetClient(),
98-
APIReader: mgr.GetAPIReader(),
99-
ClusterCache: clusterCache,
97+
Client: mgr.GetClient(),
98+
APIReader: mgr.GetAPIReader(),
99+
ClusterCache: clusterCache,
100+
RemoteConditionsGracePeriod: 5 * time.Minute,
100101
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
101102
panic(fmt.Sprintf("Failed to start MachineReconciler: %v", err))
102103
}

internal/controllers/machinedeployment/machinedeployment_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type Reconciler struct {
7979
}
8080

8181
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
82+
if r.Client == nil || r.APIReader == nil {
83+
return errors.New("Client and APIReader must not be nil")
84+
}
85+
8286
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machinedeployment")
8387
clusterToMachineDeployments, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineDeploymentList{}, mgr.GetScheme())
8488
if err != nil {

internal/controllers/machinedeployment/suite_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ func TestMain(m *testing.M) {
9191
}
9292

9393
if err := (&machinecontroller.Reconciler{
94-
Client: mgr.GetClient(),
95-
APIReader: mgr.GetAPIReader(),
96-
ClusterCache: clusterCache,
94+
Client: mgr.GetClient(),
95+
APIReader: mgr.GetAPIReader(),
96+
ClusterCache: clusterCache,
97+
RemoteConditionsGracePeriod: 5 * time.Minute,
9798
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
9899
panic(fmt.Sprintf("Failed to start MachineReconciler: %v", err))
99100
}

internal/controllers/machinehealthcheck/machinehealthcheck_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type Reconciler struct {
8787
}
8888

8989
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
90+
if r.Client == nil || r.ClusterCache == nil {
91+
return errors.New("Client and ClusterCache must not be nil")
92+
}
93+
9094
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machinehealthcheck")
9195
c, err := ctrl.NewControllerManagedBy(mgr).
9296
For(&clusterv1.MachineHealthCheck{}).

internal/controllers/machinehealthcheck/suite_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ func TestMain(m *testing.M) {
9393
SetConnectionCreationRetryInterval(2 * time.Second)
9494

9595
if err := (&clustercontroller.Reconciler{
96-
Client: mgr.GetClient(),
97-
APIReader: mgr.GetClient(),
98-
ClusterCache: clusterCache,
96+
Client: mgr.GetClient(),
97+
APIReader: mgr.GetClient(),
98+
ClusterCache: clusterCache,
99+
RemoteConnectionGracePeriod: 50 * time.Second,
99100
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
100101
panic(fmt.Sprintf("Failed to start ClusterReconciler: %v", err))
101102
}
@@ -106,9 +107,10 @@ func TestMain(m *testing.M) {
106107
panic(fmt.Sprintf("Failed to start Reconciler : %v", err))
107108
}
108109
if err := (&machinecontroller.Reconciler{
109-
Client: mgr.GetClient(),
110-
APIReader: mgr.GetAPIReader(),
111-
ClusterCache: clusterCache,
110+
Client: mgr.GetClient(),
111+
APIReader: mgr.GetAPIReader(),
112+
ClusterCache: clusterCache,
113+
RemoteConditionsGracePeriod: 5 * time.Minute,
112114
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
113115
panic(fmt.Sprintf("Failed to start MachineReconciler: %v", err))
114116
}

internal/controllers/machineset/machineset_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ type Reconciler struct {
102102
}
103103

104104
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
105+
if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil {
106+
return errors.New("Client, APIReader and ClusterCache must not be nil")
107+
}
108+
105109
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machineset")
106110
clusterToMachineSets, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineSetList{}, mgr.GetScheme())
107111
if err != nil {

internal/controllers/machineset/suite_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ func TestMain(m *testing.M) {
9797
panic(fmt.Sprintf("Failed to start MMachineSetReconciler: %v", err))
9898
}
9999
if err := (&machinecontroller.Reconciler{
100-
Client: mgr.GetClient(),
101-
APIReader: mgr.GetAPIReader(),
102-
ClusterCache: clusterCache,
100+
Client: mgr.GetClient(),
101+
APIReader: mgr.GetAPIReader(),
102+
ClusterCache: clusterCache,
103+
RemoteConditionsGracePeriod: 5 * time.Minute,
103104
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
104105
panic(fmt.Sprintf("Failed to start MachineReconciler: %v", err))
105106
}

internal/controllers/topology/cluster/cluster_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ type Reconciler struct {
8989
}
9090

9191
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
92+
if r.Client == nil || r.APIReader == nil || r.ClusterCache == nil {
93+
return errors.New("Client, APIReader and ClusterCache must not be nil")
94+
}
95+
9296
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "topology/cluster")
9397
c, err := ctrl.NewControllerManagedBy(mgr).
9498
For(&clusterv1.Cluster{}, builder.WithPredicates(

internal/controllers/topology/cluster/suite_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"sigs.k8s.io/cluster-api/controllers/remote"
3939
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
4040
"sigs.k8s.io/cluster-api/internal/controllers/clusterclass"
41+
fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake"
4142
"sigs.k8s.io/cluster-api/internal/test/envtest"
4243
)
4344

@@ -94,7 +95,8 @@ func TestMain(m *testing.M) {
9495
panic(fmt.Sprintf("unable to create topology cluster reconciler: %v", err))
9596
}
9697
if err := (&clusterclass.Reconciler{
97-
Client: mgr.GetClient(),
98+
Client: mgr.GetClient(),
99+
RuntimeClient: fakeruntimeclient.NewRuntimeClientBuilder().Build(),
98100
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 5}); err != nil {
99101
panic(fmt.Sprintf("unable to create clusterclass reconciler: %v", err))
100102
}

internal/controllers/topology/machinedeployment/machinedeployment_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ type Reconciler struct {
5959
}
6060

6161
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
62+
if r.Client == nil || r.APIReader == nil {
63+
return errors.New("Client and APIReader must not be nil")
64+
}
65+
6266
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "topology/machinedeployment")
6367
clusterToMachineDeployments, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineDeploymentList{}, mgr.GetScheme())
6468
if err != nil {

internal/controllers/topology/machineset/machineset_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type Reconciler struct {
6161
}
6262

6363
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
64+
if r.Client == nil || r.APIReader == nil {
65+
return errors.New("Client and APIReader must not be nil")
66+
}
67+
6468
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "topology/machineset")
6569
clusterToMachineSets, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineSetList{}, mgr.GetScheme())
6670
if err != nil {

internal/webhooks/test/suite_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/cluster-api/api/v1beta1/index"
3030
"sigs.k8s.io/cluster-api/feature"
3131
"sigs.k8s.io/cluster-api/internal/controllers/clusterclass"
32+
fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake"
3233
"sigs.k8s.io/cluster-api/internal/test/envtest"
3334
)
3435

@@ -48,7 +49,8 @@ func TestMain(m *testing.M) {
4849
}
4950
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
5051
if err := (&clusterclass.Reconciler{
51-
Client: mgr.GetClient(),
52+
Client: mgr.GetClient(),
53+
RuntimeClient: fakeruntimeclient.NewRuntimeClientBuilder().Build(),
5254
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 5}); err != nil {
5355
panic(fmt.Sprintf("unable to create clusterclass reconciler: %v", err))
5456
}

test/infrastructure/docker/exp/controllers/alias.go

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package controllers
2020
import (
2121
"context"
2222

23-
"k8s.io/apimachinery/pkg/runtime"
2423
ctrl "sigs.k8s.io/controller-runtime"
2524
"sigs.k8s.io/controller-runtime/pkg/client"
2625
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -32,7 +31,6 @@ import (
3231
// DockerMachinePoolReconciler reconciles a DockerMachinePool object.
3332
type DockerMachinePoolReconciler struct {
3433
Client client.Client
35-
Scheme *runtime.Scheme
3634
ContainerRuntime container.Runtime
3735

3836
// WatchFilterValue is the label value used to filter events prior to reconciliation.
@@ -43,7 +41,6 @@ type DockerMachinePoolReconciler struct {
4341
func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
4442
return (&dockermachinepoolcontrollers.DockerMachinePoolReconciler{
4543
Client: r.Client,
46-
Scheme: r.Scheme,
4744
ContainerRuntime: r.ContainerRuntime,
4845
WatchFilterValue: r.WatchFilterValue,
4946
}).SetupWithManager(ctx, mgr, options)

test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/pkg/errors"
2626
apierrors "k8s.io/apimachinery/pkg/api/errors"
27-
"k8s.io/apimachinery/pkg/runtime"
2827
"k8s.io/apimachinery/pkg/runtime/schema"
2928
"k8s.io/apimachinery/pkg/types"
3029
kerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -63,7 +62,6 @@ const (
6362
// DockerMachinePoolReconciler reconciles a DockerMachinePool object.
6463
type DockerMachinePoolReconciler struct {
6564
Client client.Client
66-
Scheme *runtime.Scheme
6765
ContainerRuntime container.Runtime
6866

6967
// WatchFilterValue is the label value used to filter events prior to reconciliation.
@@ -157,6 +155,10 @@ func (r *DockerMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Re
157155

158156
// SetupWithManager will add watches for this controller.
159157
func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
158+
if r.Client == nil || r.ContainerRuntime == nil {
159+
return errors.New("Client and ContainerRuntime must not be nil")
160+
}
161+
160162
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "dockermachinepool")
161163
clusterToDockerMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &infraexpv1.DockerMachinePoolList{}, mgr.GetScheme())
162164
if err != nil {

test/infrastructure/docker/internal/controllers/dockercluster_controller.go

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ func (r *DockerClusterReconciler) reconcileDelete(ctx context.Context, dockerClu
202202

203203
// SetupWithManager will add watches for this controller.
204204
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
205+
if r.Client == nil || r.ContainerRuntime == nil {
206+
return errors.New("Client and ContainerRuntime must not be nil")
207+
}
205208
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "dockercluster")
206209
err := ctrl.NewControllerManagedBy(mgr).
207210
For(&infrav1.DockerCluster{}).

test/infrastructure/docker/internal/controllers/dockermachine_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ func (r *DockerMachineReconciler) reconcileDelete(ctx context.Context, dockerClu
476476

477477
// SetupWithManager will add watches for this controller.
478478
func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
479+
if r.Client == nil || r.ContainerRuntime == nil || r.ClusterCache == nil {
480+
return errors.New("Client, ContainerRuntime and ClusterCache must not be nil")
481+
}
482+
479483
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "dockermachine")
480484
clusterToDockerMachines, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &infrav1.DockerMachineList{}, mgr.GetScheme())
481485
if err != nil {

test/infrastructure/inmemory/internal/controllers/inmemorycluster_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ func (r *InMemoryClusterReconciler) reconcileDelete(_ context.Context, cluster *
212212

213213
// SetupWithManager will add watches for this controller.
214214
func (r *InMemoryClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
215+
if r.Client == nil || r.InMemoryManager == nil || r.APIServerMux == nil {
216+
return errors.New("Client, InMemoryManager and APIServerMux must not be nil")
217+
}
218+
215219
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "inmemorycluster")
216220
err := ctrl.NewControllerManagedBy(mgr).
217221
For(&infrav1.InMemoryCluster{}).

test/infrastructure/inmemory/internal/controllers/inmemorymachine_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,10 @@ func (r *InMemoryMachineReconciler) reconcileDeleteControllerManager(ctx context
11511151

11521152
// SetupWithManager will add watches for this controller.
11531153
func (r *InMemoryMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
1154+
if r.Client == nil || r.InMemoryManager == nil || r.APIServerMux == nil {
1155+
return errors.New("Client, InMemoryManager and APIServerMux must not be nil")
1156+
}
1157+
11541158
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "inmemorymachine")
11551159
clusterToInMemoryMachines, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &infrav1.InMemoryMachineList{}, mgr.GetScheme())
11561160
if err != nil {

0 commit comments

Comments
 (0)