Skip to content

Commit f4582ea

Browse files
troy0820k8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
update subresource client to not incude metadata
Signed-off-by: Troy Connor <[email protected]>
1 parent 94cefd3 commit f4582ea

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pkg/client/fake/client.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,30 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
11081108
func (sw *fakeSubResourceClient) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error {
11091109
updateOptions := client.SubResourceUpdateOptions{}
11101110
updateOptions.ApplyOptions(opts)
1111-
1112-
body := obj
1113-
if updateOptions.SubResourceBody != nil {
1114-
body = updateOptions.SubResourceBody
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"))
11151133
}
1116-
return sw.client.update(body, true, &updateOptions.UpdateOptions)
1134+
return sw.client.update(bodyObj, true, &updateOptions.UpdateOptions)
11171135
}
11181136

11191137
func (sw *fakeSubResourceClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error {

0 commit comments

Comments
 (0)