@@ -400,9 +400,10 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
400400
401401if t .withStatusSubresource .Has (gvk ) {
402402if 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 {
404404return 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
407408if err := copyStatusFrom (oldObject , obj ); err != nil {
408409return fmt .Errorf ("failed to copy the status for object with status subresource: %w" , err )
@@ -949,6 +950,7 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
949950return obj , nil
950951}
951952
953+ //lint:ignore U1000 function is causing errors with status updates
952954func copyNonStatusFrom (old , new runtime.Object ) error {
953955newClientObject , ok := new .(client.Object )
954956if ! ok {
@@ -1108,30 +1110,12 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
11081110func (sw * fakeSubResourceClient ) Update (ctx context.Context , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
11091111updateOptions := client.SubResourceUpdateOptions {}
11101112updateOptions .ApplyOptions (opts )
1111- gvr , err := getGVRFromObject (obj , sw .client .scheme )
1112- if err != nil {
1113- return err
1114- }
1115- o , err := sw .client .tracker .Get (gvr , obj .GetNamespace (), obj .GetName ())
1116- if err != nil {
1117- return err
1118- }
1119- gvk , err := apiutil .GVKForObject (obj , sw .client .scheme )
1120- if err != nil {
1121- return err
1122- }
1123- body := o
1124- if sw .client .tracker .withStatusSubresource .Has (gvk ) {
1125- err := copyStatusFrom (obj , body )
1126- if err != nil {
1127- return err
1128- }
1129- }
1130- bodyObj := body .(client.Object )
1131- if bodyObj .GetResourceVersion () != obj .GetResourceVersion () {
1132- return apierrors .NewConflict (gvr .GroupResource (), obj .GetName (), fmt .Errorf ("resource version conflict" ))
1113+
1114+ body := obj
1115+ if updateOptions .SubResourceBody != nil {
1116+ body = updateOptions .SubResourceBody
11331117}
1134- return sw .client .update (bodyObj , true , & updateOptions .UpdateOptions )
1118+ return sw .client .update (body , true , & updateOptions .UpdateOptions )
11351119}
11361120
11371121func (sw * fakeSubResourceClient ) Patch (ctx context.Context , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error {
0 commit comments