Skip to content

Commit

Permalink
update subresource client to not incude metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 authored and k8s-infra-cherrypick-robot committed Sep 9, 2023
1 parent 94cefd3 commit f4582ea
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,30 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
func (sw *fakeSubResourceClient) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error {
updateOptions := client.SubResourceUpdateOptions{}
updateOptions.ApplyOptions(opts)

body := obj
if updateOptions.SubResourceBody != nil {
body = updateOptions.SubResourceBody
gvr, err := getGVRFromObject(obj, sw.client.scheme)
if err != nil {
return err
}
o, err := sw.client.tracker.Get(gvr, obj.GetNamespace(), obj.GetName())
if err != nil {
return err
}
gvk, err := apiutil.GVKForObject(obj, sw.client.scheme)
if err != nil {
return err
}
body := o
if sw.client.tracker.withStatusSubresource.Has(gvk) {
err := copyStatusFrom(obj, body)
if err != nil {
return err
}
}
bodyObj := body.(client.Object)
if bodyObj.GetResourceVersion() != obj.GetResourceVersion() {
return apierrors.NewConflict(gvr.GroupResource(), obj.GetName(), fmt.Errorf("resource version conflict"))
}
return sw.client.update(body, true, &updateOptions.UpdateOptions)
return sw.client.update(bodyObj, true, &updateOptions.UpdateOptions)
}

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

0 comments on commit f4582ea

Please sign in to comment.