@@ -400,9 +400,10 @@ func (t versionedTracker) update(gvr schema.GroupVersionResource, obj runtime.Ob
400
400
401
401
if t .withStatusSubresource .Has (gvk ) {
402
402
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 {
404
404
return fmt .Errorf ("failed to copy non-status field for object with status subresouce: %w" , err )
405
405
}
406
+ obj = oldObject .DeepCopyObject ().(client.Object )
406
407
} else { // copy status from original object
407
408
if err := copyStatusFrom (oldObject , obj ); err != nil {
408
409
return 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
949
950
return obj , nil
950
951
}
951
952
953
+ //lint:ignore U1000 function is causing errors with status updates
952
954
func copyNonStatusFrom (old , new runtime.Object ) error {
953
955
newClientObject , ok := new .(client.Object )
954
956
if ! ok {
@@ -1108,30 +1110,12 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
1108
1110
func (sw * fakeSubResourceClient ) Update (ctx context.Context , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
1109
1111
updateOptions := client.SubResourceUpdateOptions {}
1110
1112
updateOptions .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
1133
1117
}
1134
- return sw .client .update (bodyObj , true , & updateOptions .UpdateOptions )
1118
+ return sw .client .update (body , true , & updateOptions .UpdateOptions )
1135
1119
}
1136
1120
1137
1121
func (sw * fakeSubResourceClient ) Patch (ctx context.Context , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error {
0 commit comments