Skip to content

Commit 8ac8d8e

Browse files
committed
Rework code to pass object back on status update
1 parent c527239 commit 8ac8d8e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

pkg/client/fake/client.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ 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-
407-
obj = oldObject.DeepCopyObject().(client.Object)
406+
passedRV := accessor.GetResourceVersion()
407+
reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(oldObject.DeepCopyObject()).Elem())
408+
accessor.SetResourceVersion(passedRV)
408409
} else { // copy status from original object
409410
if err := copyStatusFrom(oldObject, obj); err != nil {
410411
return fmt.Errorf("failed to copy the status for object with status subresource: %w", err)
@@ -437,14 +438,6 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
437438
intResourceVersion++
438439
accessor.SetResourceVersion(strconv.FormatUint(intResourceVersion, 10))
439440

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-
448441
if !deleting && !deletionTimestampEqual(accessor, oldAccessor) {
449442
return fmt.Errorf("error: Unable to edit %s: metadata.deletionTimestamp field is immutable", accessor.GetName())
450443
}

0 commit comments

Comments
 (0)