Skip to content

Commit

Permalink
Draft: ensure we udpate the new obj's accessor's ResourceVersion afte…
Browse files Browse the repository at this point in the history
…r doing the deep copy
  • Loading branch information
berlin-ab committed Sep 10, 2023
1 parent 8f0fe71 commit c527239
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
if err := copyStatusFrom(obj, oldObject); err != nil {
return fmt.Errorf("failed to copy non-status field for object with status subresouce: %w", err)
}

obj = oldObject.DeepCopyObject().(client.Object)
} else { // copy status from original object
if err := copyStatusFrom(oldObject, obj); err != nil {
Expand Down Expand Up @@ -436,6 +437,14 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
intResourceVersion++
accessor.SetResourceVersion(strconv.FormatUint(intResourceVersion, 10))

// obtain the current obj accessor's pointer,
// so we can make an update on the current obj
currentAccessor, err := meta.Accessor(obj)
if err != nil {
return fmt.Errorf("failed to get accessor for object: %w", err)
}
currentAccessor.SetResourceVersion(strconv.FormatUint(intResourceVersion, 10))

if !deleting && !deletionTimestampEqual(accessor, oldAccessor) {
return fmt.Errorf("error: Unable to edit %s: metadata.deletionTimestamp field is immutable", accessor.GetName())
}
Expand Down

0 comments on commit c527239

Please sign in to comment.