From 7d32c63592a438cd6084fd4ff4dfc2ae39176552 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 30 Dec 2022 16:23:34 +0100 Subject: [PATCH 1/4] Add additional SubResource* functions for FieldOwner This enhances #2072 to allow FieldOwner work with SubResources to set the FieldManager option. --- pkg/client/options.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/client/options.go b/pkg/client/options.go index c8fa0dc797..7a788f1b80 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -154,6 +154,23 @@ func (f FieldOwner) ApplyToUpdate(opts *UpdateOptions) { opts.FieldManager = string(f) } +// ApplyToSubResourcePatch applies this configuration to the given patch options. +func (f FieldOwner) ApplyToSubResourcePatch(opts *SubResourcePatchOptions) { + opts.FieldManager = string(f) +} + +// ApplyToSubResourceCreate applies this configuration to the given create options. +func (f FieldOwner) ApplyToSubResourceCreate(opts *SubResourceCreateOptions) { + opts.FieldManager = string(f) +} + +// ApplyToSubResourceUpdate applies this configuration to the given update options. +func (f FieldOwner) ApplyToSubResourceUpdate(opts *SubResourceUpdateOptions) { + opts.FieldManager = string(f) +} + + + // }}} // {{{ Create Options From 831d94cabaee661fb3f1976aea864218cf58f9a0 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 2 Jan 2023 09:42:14 +0100 Subject: [PATCH 2/4] Typos --- pkg/client/options_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index ca7ee0fb08..8dcd356161 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -86,27 +86,27 @@ var _ = Describe("GetOptions", func() { var _ = Describe("CreateOptions", func() { It("Should set DryRun", func() { o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}} - newCreatOpts := &client.CreateOptions{} - o.ApplyToCreate(newCreatOpts) - Expect(newCreatOpts).To(Equal(o)) + newCreateOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreateOpts) + Expect(newCreateOpts).To(Equal(o)) }) It("Should set FieldManager", func() { o := &client.CreateOptions{FieldManager: "FieldManager"} - newCreatOpts := &client.CreateOptions{} - o.ApplyToCreate(newCreatOpts) - Expect(newCreatOpts).To(Equal(o)) + newCreateOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreateOpts) + Expect(newCreateOpts).To(Equal(o)) }) It("Should set Raw", func() { o := &client.CreateOptions{Raw: &metav1.CreateOptions{DryRun: []string{"Bye", "Theodore"}}} - newCreatOpts := &client.CreateOptions{} - o.ApplyToCreate(newCreatOpts) - Expect(newCreatOpts).To(Equal(o)) + newCreateOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreateOpts) + Expect(newCreateOpts).To(Equal(o)) }) It("Should not set anything", func() { o := &client.CreateOptions{} - newCreatOpts := &client.CreateOptions{} - o.ApplyToCreate(newCreatOpts) - Expect(newCreatOpts).To(Equal(o)) + newCreateOpts := &client.CreateOptions{} + o.ApplyToCreate(newCreateOpts) + Expect(newCreateOpts).To(Equal(o)) }) }) From a3fd52f827fd2c30fddfee9104bf4b7011f87c2f Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 2 Jan 2023 09:50:55 +0100 Subject: [PATCH 3/4] Apply gofmt -s --- pkg/client/options.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/client/options.go b/pkg/client/options.go index 7a788f1b80..7f6f5b83ff 100644 --- a/pkg/client/options.go +++ b/pkg/client/options.go @@ -169,8 +169,6 @@ func (f FieldOwner) ApplyToSubResourceUpdate(opts *SubResourceUpdateOptions) { opts.FieldManager = string(f) } - - // }}} // {{{ Create Options From b1b229b7d529a20a31b329298f4ff4bdf9b8e06a Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 2 Jan 2023 10:00:26 +0100 Subject: [PATCH 4/4] Add tests for FieldOwner --- pkg/client/options_test.go | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/client/options_test.go b/pkg/client/options_test.go index 8dcd356161..8885ca3544 100644 --- a/pkg/client/options_test.go +++ b/pkg/client/options_test.go @@ -238,3 +238,42 @@ var _ = Describe("MatchingLabels", func() { Expect(err.Error()).To(Equal(expectedErrMsg)) }) }) + +var _ = Describe("FieldOwner", func() { + It("Should apply to PatchOptions", func() { + o := &client.PatchOptions{FieldManager: "bar"} + t := client.FieldOwner("foo") + t.ApplyToPatch(o) + Expect(o.FieldManager).To(Equal("foo")) + }) + It("Should apply to CreateOptions", func() { + o := &client.CreateOptions{FieldManager: "bar"} + t := client.FieldOwner("foo") + t.ApplyToCreate(o) + Expect(o.FieldManager).To(Equal("foo")) + }) + It("Should apply to UpdateOptions", func() { + o := &client.UpdateOptions{FieldManager: "bar"} + t := client.FieldOwner("foo") + t.ApplyToUpdate(o) + Expect(o.FieldManager).To(Equal("foo")) + }) + It("Should apply to SubResourcePatchOptions", func() { + o := &client.SubResourcePatchOptions{PatchOptions: client.PatchOptions{FieldManager: "bar"}} + t := client.FieldOwner("foo") + t.ApplyToSubResourcePatch(o) + Expect(o.FieldManager).To(Equal("foo")) + }) + It("Should apply to SubResourceCreateOptions", func() { + o := &client.SubResourceCreateOptions{CreateOptions: client.CreateOptions{FieldManager: "bar"}} + t := client.FieldOwner("foo") + t.ApplyToSubResourceCreate(o) + Expect(o.FieldManager).To(Equal("foo")) + }) + It("Should apply to SubResourceUpdateOptions", func() { + o := &client.SubResourceUpdateOptions{UpdateOptions: client.UpdateOptions{FieldManager: "bar"}} + t := client.FieldOwner("foo") + t.ApplyToSubResourceUpdate(o) + Expect(o.FieldManager).To(Equal("foo")) + }) +})