From 8ac8d8e6408c04bc2664ab5f358444b930892eee Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Sun, 10 Sep 2023 15:52:15 -0400 Subject: [PATCH] Rework code to pass object back on status update --- pkg/client/fake/client.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/client/fake/client.go b/pkg/client/fake/client.go index d4a47c0974..d70237e950 100644 --- a/pkg/client/fake/client.go +++ b/pkg/client/fake/client.go @@ -403,8 +403,9 @@ 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) + passedRV := accessor.GetResourceVersion() + reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(oldObject.DeepCopyObject()).Elem()) + accessor.SetResourceVersion(passedRV) } else { // copy status from original object if err := copyStatusFrom(oldObject, obj); err != nil { 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 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()) }