Skip to content

Commit c527239

Browse files
committed
Draft: ensure we udpate the new obj's accessor's ResourceVersion after doing the deep copy
1 parent 8f0fe71 commit c527239

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/client/fake/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
403403
if err := copyStatusFrom(obj, oldObject); err != nil {
404404
return fmt.Errorf("failed to copy non-status field for object with status subresouce: %w", err)
405405
}
406+
406407
obj = oldObject.DeepCopyObject().(client.Object)
407408
} else { // copy status from original object
408409
if err := copyStatusFrom(oldObject, obj); err != nil {
@@ -436,6 +437,14 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
436437
intResourceVersion++
437438
accessor.SetResourceVersion(strconv.FormatUint(intResourceVersion, 10))
438439

440+
// obtain the current obj accessor's pointer,
441+
// so we can make an update on the current obj
442+
currentAccessor, err := meta.Accessor(obj)
443+
if err != nil {
444+
return fmt.Errorf("failed to get accessor for object: %w", err)
445+
}
446+
currentAccessor.SetResourceVersion(strconv.FormatUint(intResourceVersion, 10))
447+
439448
if !deleting && !deletionTimestampEqual(accessor, oldAccessor) {
440449
return fmt.Errorf("error: Unable to edit %s: metadata.deletionTimestamp field is immutable", accessor.GetName())
441450
}

0 commit comments

Comments
 (0)