deepcopy original before upgradeClientSideFieldManager, as original and target share the same object, and calling Get() on original will change target, and cause target patch data to carry unwanted data loaded from live resource

Signed-off-by: wallyatgithub <30530146+wallyatgithub@users.noreply.github.com>
pull/31384/head^2
wallyatgithub 1 year ago committed by GitHub
parent 8d70995503
commit 676ca581f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -736,7 +736,10 @@ func (c *Client) Update(originals, targets ResourceList, options ...ClientUpdate
slog.String("gvk", target.Mapping.GroupVersionKind.String()))
if updateOptions.upgradeClientSideFieldManager {
patched, err := upgradeClientSideFieldManager(original, updateOptions.dryRun, updateOptions.fieldValidationDirective)
// target and original shares same Object, deep copy original to avoid changing target
copiedOriginal := *original
copiedOriginal.Object = original.Object.DeepCopyObject()
patched, err := upgradeClientSideFieldManager(&copiedOriginal, updateOptions.dryRun, updateOptions.fieldValidationDirective)
if err != nil {
slog.Debug("Error patching resource to replace CSA field management", slog.Any("error", err))
return err

Loading…
Cancel
Save