From abe8a6e81642066db1868bfff4faa9cc1bd84b95 Mon Sep 17 00:00:00 2001 From: justinsb Date: Thu, 30 Mar 2023 21:30:22 -0400 Subject: [PATCH] ForceOwnership should work with subresources Ensure that we can force when applying to subresources (in particular status) Issue #2125 --- pkg/client/options.go | 5 +++++ pkg/client/options_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index 7f6f5b83ff..14578f9140 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -788,6 +788,11 @@ func (forceOwnership) ApplyToPatch(opts *PatchOptions) { opts.Force = &definitelyTrue } +func (forceOwnership) ApplyToSubResourcePatch(opts *SubResourcePatchOptions) { + definitelyTrue := true + opts.Force = &definitelyTrue +} + // }}} // {{{ DeleteAllOf Options diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 8885ca3544..fabba6bfb8 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -277,3 +277,18 @@ var _ = Describe("FieldOwner", func() { Expect(o.FieldManager).To(Equal("foo")) }) }) + +var _ = Describe("ForceOwnership", func() { + It("Should apply to PatchOptions", func() { + o := &client.PatchOptions{} + t := client.ForceOwnership + t.ApplyToPatch(o) + Expect(o.Force).To(Equal(true)) + }) + It("Should apply to SubResourcePatchOptions", func() { + o := &client.SubResourcePatchOptions{PatchOptions: client.PatchOptions{}} + t := client.ForceOwnership + t.ApplyToSubResourcePatch(o) + Expect(o.Force).To(Equal(true)) + }) +})