Skip to content

Commit 929fa47

Browse files
Add inline comments for deep copy patching (#35)
Adds clarifying comments about why `DeepCopyObject` is necessary when using `Patch`.
1 parent 3541317 commit 929fa47

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/runtime/reconciler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ func (r *resourceReconciler) patchResourceMetadataAndSpec(
340340
}
341341

342342
rlog.Enter("kc.Patch (metadata + spec)")
343+
// It is necessary to use `DeepCopyObject` versions of `latest` when calling
344+
// `Patch` as this method overrides all values as merged from `desired`.
345+
// This may affect `latest` in later execution, as otherwise this would set
346+
//`desired` == `latest` after calling this method.
343347
err = r.kc.Patch(
344348
ctx,
345349
latest.RuntimeObject().DeepCopyObject(),
@@ -373,6 +377,10 @@ func (r *resourceReconciler) patchResourceStatus(
373377
return nil
374378
}
375379
rlog.Enter("kc.Patch (status)")
380+
// It is necessary to use `DeepCopyObject` versions of `latest` when calling
381+
// `Patch` as this method overrides all values as merged from `desired`.
382+
// This may affect `latest` in later execution, as otherwise this would set
383+
//`desired` == `latest` after calling this method.
376384
err = r.kc.Status().Patch(
377385
ctx,
378386
latest.RuntimeObject().DeepCopyObject(),

0 commit comments

Comments
 (0)