Skip to content

Commit 2550538

Browse files
committed
Use client.Client instead of client.Patch as its going to deprecated
1 parent eb4e38c commit 2550538

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ linters:
269269
- linters:
270270
- staticcheck
271271
text: 'SA1019: .*(res|result|i|j)\.Requeue is deprecated: Use `RequeueAfter` instead'
272-
# CR v0.22 deprecated client.Apply, will be fixed via: https://github.com/kubernetes-sigs/cluster-api/issues/12695
273-
- linters:
274-
- staticcheck
275-
text: 'SA1019: client.Apply is deprecated: Use client.Client.Apply'
276272
# TODO: var-naming: avoid meaningless package names by revive
277273
# * test/infrastructure/docker/internal/docker/types/
278274
# * bootstrap/kubeadm/types/

controllers/crdmigrator/crd_migrator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ func (r *CRDMigrator) reconcileStorageVersionMigration(ctx context.Context, crd
410410
log.V(4).Info("Migrating to new storage version", gvk.Kind, klog.KObj(u))
411411
var err error
412412
if migrationConfig.UseStatusForStorageVersionMigration {
413-
err = r.Client.Status().Patch(ctx, u, client.Apply, client.FieldOwner("crdmigrator"))
413+
err = r.Client.Status().Patch(ctx, u, client.Apply, client.FieldOwner("crdmigrator")) //nolint:staticcheck //Currently client.Client.Apply() does not support updating Status subresource, Tracked in https://github.com/kubernetes-sigs/controller-runtime/issues/3183
414414
} else {
415-
err = r.Client.Patch(ctx, u, client.Apply, client.FieldOwner("crdmigrator"))
415+
err = r.Client.Apply(ctx, client.ApplyConfigurationFromUnstructured(u), client.FieldOwner("crdmigrator"))
416416
}
417417
// If we got a NotFound error, the object no longer exists so no need to update it.
418418
// If we got a Conflict error, another client wrote the object already so no need to update it.

controllers/crdmigrator/crd_migrator_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ func TestReconcile(t *testing.T) {
195195
// Deploy test-cluster-1 and test-cluster-2.
196196
testClusterT1 := unstructuredTestCluster("test-cluster-1", t1v1beta1.GroupVersion.WithKind("TestCluster"))
197197
g.Expect(unstructured.SetNestedField(testClusterT1.Object, "foo-value", "spec", "foo")).To(Succeed())
198-
g.Expect(managerT1.GetClient().Patch(ctx, testClusterT1, client.Apply, fieldOwner)).To(Succeed())
198+
g.Expect(managerT1.GetClient().Apply(ctx, client.ApplyConfigurationFromUnstructured(testClusterT1), fieldOwner)).To(Succeed())
199199
testClusterT1 = unstructuredTestCluster("test-cluster-2", t1v1beta1.GroupVersion.WithKind("TestCluster"))
200200
g.Expect(unstructured.SetNestedField(testClusterT1.Object, "foo-value", "spec", "foo")).To(Succeed())
201-
g.Expect(managerT1.GetClient().Patch(ctx, testClusterT1, client.Apply, fieldOwner)).To(Succeed())
201+
g.Expect(managerT1.GetClient().Apply(ctx, client.ApplyConfigurationFromUnstructured(testClusterT1), fieldOwner)).To(Succeed())
202202
validateManagedFields(t, g, "v1beta1", map[string][]string{
203203
"test-cluster-1": {"test.cluster.x-k8s.io/v1beta1"},
204204
"test-cluster-2": {"test.cluster.x-k8s.io/v1beta1"},
@@ -226,11 +226,11 @@ func TestReconcile(t *testing.T) {
226226
// Set an additional field with a different field manager and v1beta2 apiVersion in test-cluster-2
227227
testClusterT2 := unstructuredTestCluster("test-cluster-2", t2v1beta2.GroupVersion.WithKind("TestCluster"))
228228
g.Expect(unstructured.SetNestedField(testClusterT2.Object, "bar-value", "spec", "bar")).To(Succeed())
229-
g.Expect(managerT2.GetClient().Patch(ctx, testClusterT2, client.Apply, client.FieldOwner("different-unit-test-client"))).To(Succeed())
229+
g.Expect(managerT2.GetClient().Apply(ctx, client.ApplyConfigurationFromUnstructured(testClusterT2), client.FieldOwner("different-unit-test-client"))).To(Succeed())
230230
// Deploy test-cluster-3.
231231
testClusterT2 = unstructuredTestCluster("test-cluster-3", t2v1beta2.GroupVersion.WithKind("TestCluster"))
232232
g.Expect(unstructured.SetNestedField(testClusterT2.Object, "foo-value", "spec", "foo")).To(Succeed())
233-
g.Expect(managerT2.GetClient().Patch(ctx, testClusterT2, client.Apply, fieldOwner)).To(Succeed())
233+
g.Expect(managerT2.GetClient().Apply(ctx, client.ApplyConfigurationFromUnstructured(testClusterT2), fieldOwner)).To(Succeed())
234234
// At this point we have clusters with all combinations of managedField apiVersions.
235235
validateManagedFields(t, g, "v1beta2", map[string][]string{
236236
"test-cluster-1": {"test.cluster.x-k8s.io/v1beta1"},
@@ -323,7 +323,7 @@ func TestReconcile(t *testing.T) {
323323
// Try to patch the test-clusters CRs with SSA.
324324
testClusterT4 := unstructuredTestCluster(clusterName, t4v1beta2.GroupVersion.WithKind("TestCluster"))
325325
g.Expect(unstructured.SetNestedField(testClusterT4.Object, "new-foo-value", "spec", "foo")).To(Succeed())
326-
err = managerT4.GetClient().Patch(ctx, testClusterT4, client.Apply, fieldOwner)
326+
err = managerT4.GetClient().Apply(ctx, client.ApplyConfigurationFromUnstructured(testClusterT4), fieldOwner)
327327

328328
// If managedField cleanup was skipped before, the SSA patch will fail for the clusters which still have v1beta1 managedFields.
329329
if skipCRDMigrationPhases.Has(CleanupManagedFieldsPhase) && (clusterName == "test-cluster-1" || clusterName == "test-cluster-2") {

internal/controllers/topology/cluster/structuredmerge/dryrun.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func dryRunSSAPatch(ctx context.Context, dryRunCtx *dryRunSSAPatchInput) (bool,
8181
}
8282

8383
// Do a server-side apply dry-run with modifiedUnstructured to get the updated object.
84-
err = dryRunCtx.client.Patch(ctx, dryRunCtx.modifiedUnstructured, client.Apply, client.DryRunAll, client.FieldOwner(TopologyManagerName), client.ForceOwnership)
84+
err = dryRunCtx.client.Apply(ctx, client.ApplyConfigurationFromUnstructured(dryRunCtx.modifiedUnstructured), client.DryRunAll, client.FieldOwner(TopologyManagerName), client.ForceOwnership)
8585
if err != nil {
8686
// This catches errors like metadata.uid changes.
8787
return false, false, nil, errors.Wrap(err, "server side apply dry-run failed for modified object")
@@ -107,7 +107,7 @@ func dryRunSSAPatch(ctx context.Context, dryRunCtx *dryRunSSAPatchInput) (bool,
107107
// Note: Otherwise we would get the following error:
108108
// "failed to request dry-run server side apply: metadata.managedFields must be nil"
109109
dryRunCtx.originalUnstructured.SetManagedFields(nil)
110-
err = dryRunCtx.client.Patch(ctx, dryRunCtx.originalUnstructured, client.Apply, client.DryRunAll, client.FieldOwner(TopologyManagerName), client.ForceOwnership)
110+
err = dryRunCtx.client.Apply(ctx, client.ApplyConfigurationFromUnstructured(dryRunCtx.originalUnstructured), client.DryRunAll, client.FieldOwner(TopologyManagerName), client.ForceOwnership)
111111
if err != nil {
112112
return false, false, nil, errors.Wrap(err, "server side apply dry-run failed for original object")
113113
}

internal/controllers/topology/cluster/structuredmerge/serversidepathhelper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ func (h *serverSidePatchHelper) Patch(ctx context.Context) error {
141141
log := ctrl.LoggerFrom(ctx)
142142
log.V(5).Info("Patching object", "intent", h.modified)
143143

144-
options := []client.PatchOption{
144+
options := []client.ApplyOption{
145145
client.FieldOwner(TopologyManagerName),
146146
// NOTE: we are using force ownership so in case of conflicts the topology controller
147147
// overwrite values and become sole manager.
148148
client.ForceOwnership,
149149
}
150-
return h.client.Patch(ctx, h.modified, client.Apply, options...)
150+
return h.client.Apply(ctx, client.ApplyConfigurationFromUnstructured(h.modified), options...)
151151
}

internal/util/ssa/patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ func Patch(ctx context.Context, c client.Client, fieldManager string, modified c
9999
}
100100
}
101101

102-
patchOptions := []client.PatchOption{
102+
applyOptions := []client.ApplyOption{
103103
client.ForceOwnership,
104104
client.FieldOwner(fieldManager),
105105
}
106-
if err := c.Patch(ctx, modifiedUnstructured, client.Apply, patchOptions...); err != nil {
106+
if err := c.Apply(ctx, client.ApplyConfigurationFromUnstructured(modifiedUnstructured), applyOptions...); err != nil {
107107
return errors.Wrapf(err, "failed to apply %s %s", gvk.Kind, klog.KObj(modifiedUnstructured))
108108
}
109109

0 commit comments

Comments
 (0)