Skip to content

Commit

Permalink
test: pass WithStatusSubresource to the fake client
Browse files Browse the repository at this point in the history
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 <mko@redhat.com>
  • Loading branch information
mkowalski committed Oct 20, 2023
1 parent 04ad85b commit 3866124
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/handler/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var _ = Describe("Node controller reconcile", func() {
objs := []runtime.Object{&node, &nodenetworkstate}

// Create a fake client to mock API calls.
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).WithStatusSubresource(&nmstatev1beta1.NodeNetworkState{}).Build()

reconciler.Client = cl
reconciler.Log = ctrl.Log.WithName("controllers").WithName("Node")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = Describe("Node Network Configuration Enactment controller reconcile", fu
objs := []runtime.Object{&policy, &enactment}

// Create a fake client to mock API calls.
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).WithStatusSubresource(&nmstatev1beta1.NodeNetworkConfigurationEnactment{}).Build()

reconciler.Client = cl
reconciler.Log = ctrl.Log.WithName("controllers").WithName("Enactment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var _ = Describe("NodeNetworkConfigurationPolicy controller predicates", func()
clb := fake.ClientBuilder{}
clb.WithScheme(s)
clb.WithRuntimeObjects(objs...)
clb.WithStatusSubresource(&nmstatev1beta1.NodeNetworkConfigurationEnactment{}, &nmstatev1.NodeNetworkConfigurationPolicy{})
cl := clb.Build()

reconciler.Client = cl
Expand Down
2 changes: 1 addition & 1 deletion controllers/operator/nmstate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var _ = Describe("NMState controller reconcile", func() {
)
objs := []runtime.Object{&nmstate}
// Create a fake client to mock API calls.
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).WithStatusSubresource(&nmstatev1.NMState{}).Build()
names.ManifestDir = manifestsDir
reconciler.Client = cl
reconciler.APIClient = cl
Expand Down
2 changes: 1 addition & 1 deletion pkg/policyconditions/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var _ = Describe("Policy Conditions", func() {

objs = append(objs, updatedPolicy)

client := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
client := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).WithStatusSubresource(&nmstatev1.NodeNetworkConfigurationPolicy{}).Build()
key := types.NamespacedName{Name: updatedPolicy.Name}
err := Update(client, client, key)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 3866124

Please sign in to comment.