Skip to content

Commit 86cc0b0

Browse files
committed
test: pass WithStatusSubresource to the fake client
With the upgrade to controller-runtime v0.15 we need to supplement the fake builder to contain instantiation `WithStatusSubresource` in order to be able to update status of the object that we have created. In previous versions of controller-runtime this was not necessary because the semantics was ignored but in v0.15 the fake client cannot infer the status subresource without its explicit instantiation. Ref.: kubernetes-sigs/controller-runtime#2362 Signed-off-by: Mat Kowalski <[email protected]>
1 parent b96402a commit 86cc0b0

5 files changed

+28
-4
lines changed

controllers/handler/node_controller_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ var _ = Describe("Node controller reconcile", func() {
8282
objs := []runtime.Object{&node, &nodenetworkstate}
8383

8484
// Create a fake client to mock API calls.
85-
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
85+
cl = fake.
86+
NewClientBuilder().
87+
WithScheme(s).
88+
WithRuntimeObjects(objs...).
89+
WithStatusSubresource(&nmstatev1beta1.NodeNetworkState{}).
90+
Build()
8691

8792
reconciler.Client = cl
8893
reconciler.Log = ctrl.Log.WithName("controllers").WithName("Node")

controllers/handler/nodenetworkconfigurationenactment_controller_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ var _ = Describe("Node Network Configuration Enactment controller reconcile", fu
8383
objs := []runtime.Object{&policy, &enactment}
8484

8585
// Create a fake client to mock API calls.
86-
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
86+
cl = fake.
87+
NewClientBuilder().
88+
WithScheme(s).
89+
WithRuntimeObjects(objs...).
90+
WithStatusSubresource(&nmstatev1beta1.NodeNetworkConfigurationEnactment{}).
91+
Build()
8792

8893
reconciler.Client = cl
8994
reconciler.Log = ctrl.Log.WithName("controllers").WithName("Enactment")

controllers/handler/nodenetworkconfigurationpolicy_controller_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ var _ = Describe("NodeNetworkConfigurationPolicy controller predicates", func()
143143
clb := fake.ClientBuilder{}
144144
clb.WithScheme(s)
145145
clb.WithRuntimeObjects(objs...)
146+
clb.WithStatusSubresource(
147+
&nmstatev1beta1.NodeNetworkConfigurationEnactment{},
148+
&nmstatev1.NodeNetworkConfigurationPolicy{},
149+
)
146150
cl := clb.Build()
147151

148152
reconciler.Client = cl

controllers/operator/nmstate_controller_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ var _ = Describe("NMState controller reconcile", func() {
9393
)
9494
objs := []runtime.Object{&nmstate}
9595
// Create a fake client to mock API calls.
96-
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
96+
cl = fake.
97+
NewClientBuilder().
98+
WithScheme(s).
99+
WithRuntimeObjects(objs...).
100+
WithStatusSubresource(&nmstatev1.NMState{}).
101+
Build()
97102
names.ManifestDir = manifestsDir
98103
reconciler.Client = cl
99104
reconciler.APIClient = cl

pkg/policyconditions/conditions_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ var _ = Describe("Policy Conditions", func() {
211211

212212
objs = append(objs, updatedPolicy)
213213

214-
client := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
214+
client := fake.
215+
NewClientBuilder().
216+
WithScheme(s).
217+
WithRuntimeObjects(objs...).
218+
WithStatusSubresource(&nmstatev1.NodeNetworkConfigurationPolicy{}).
219+
Build()
215220
key := types.NamespacedName{Name: updatedPolicy.Name}
216221
err := Update(client, client, key)
217222
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)