@@ -400,9 +400,10 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
400400
401401 if t .withStatusSubresource .Has (gvk ) {
402402 if isStatus { // copy everything but status and metadata.ResourceVersion from original object
403- if err := copyNonStatusFrom ( oldObject , obj ); err != nil {
403+ 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+ obj = oldObject .DeepCopyObject ().(client.Object )
406407 } else { // copy status from original object
407408 if err := copyStatusFrom (oldObject , obj ); err != nil {
408409 return fmt .Errorf ("failed to copy the status for object with status subresource: %w" , err )
@@ -949,45 +950,6 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
949950 return obj , nil
950951}
951952
952- func copyNonStatusFrom (old , new runtime.Object ) error {
953- newClientObject , ok := new .(client.Object )
954- if ! ok {
955- return fmt .Errorf ("%T is not a client.Object" , new )
956- }
957- // The only thing other than status we have to retain
958- rv := newClientObject .GetResourceVersion ()
959-
960- oldMapStringAny , err := toMapStringAny (old )
961- if err != nil {
962- return fmt .Errorf ("failed to convert old to *unstructured.Unstructured: %w" , err )
963- }
964- newMapStringAny , err := toMapStringAny (new )
965- if err != nil {
966- return fmt .Errorf ("failed to convert new to *unststructured.Unstructured: %w" , err )
967- }
968-
969- // delete everything other than status in case it has fields that were not present in
970- // the old object
971- for k := range newMapStringAny {
972- if k != "status" {
973- delete (newMapStringAny , k )
974- }
975- }
976- // copy everything other than status from the old object
977- for k := range oldMapStringAny {
978- if k != "status" {
979- newMapStringAny [k ] = oldMapStringAny [k ]
980- }
981- }
982-
983- if err := fromMapStringAny (newMapStringAny , new ); err != nil {
984- return fmt .Errorf ("failed to convert back from map[string]any: %w" , err )
985- }
986- newClientObject .SetResourceVersion (rv )
987-
988- return nil
989- }
990-
991953// copyStatusFrom copies the status from old into new
992954func copyStatusFrom (old , new runtime.Object ) error {
993955 oldMapStringAny , err := toMapStringAny (old )
0 commit comments