From f4582ea9b6a3dfa034be50d9bba47a13c1643c20 Mon Sep 17 00:00:00 2001 From: Troy Connor Date: Fri, 8 Sep 2023 16:58:07 -0400 Subject: [PATCH] update subresource client to not incude metadata Signed-off-by: Troy Connor --- pkg/client/fake/client.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/client/fake/client.go b/pkg/client/fake/client.go index 48d80bd4f9..18dd639d1c 100644 --- a/pkg/client/fake/client.go +++ b/pkg/client/fake/client.go @@ -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 {