Skip to content

Commit 11aa2af

Browse files
authored
Update client.md (#2642)
With the patch examples provided, no changes would actually occur when patching because the patch was being applied to the modified object instead of a copy of the original.
1 parent 5706322 commit 11aa2af

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

doc/user/client.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e
275275
...
276276

277277
ctx := context.TODO()
278-
dep.Spec.Selector.MatchLabels["is_running"] = "true"
279278
// A merge patch will preserve other fields modified at runtime.
280-
patch := client.MergeFrom(dep)
279+
patch := client.MergeFrom(dep.DeepCopy())
280+
dep.Spec.Selector.MatchLabels["is_running"] = "true"
281281
err := r.client.Patch(ctx, dep, patch)
282282

283283
...
@@ -326,7 +326,8 @@ func (r *ReconcileApp) Reconcile(request reconcile.Request) (reconcile.Result, e
326326
...
327327

328328
// Patch
329-
patch := client.MergeFrom(mem)
329+
patch := client.MergeFrom(mem.DeepCopy())
330+
mem.Status.Nodes = []string{"pod1", "pod2", "pod3"}
330331
err := r.client.Status().Patch(ctx, mem, patch)
331332

332333
...

0 commit comments

Comments
 (0)