Skip to content

Commit d3120b6

Browse files
authored
✨ Add additional SubResource* functions for FieldOwner (#2115)
* Add additional SubResource* functions for FieldOwner This enhances #2072 to allow FieldOwner work with SubResources to set the FieldManager option. * Typos * Apply gofmt -s * Add tests for FieldOwner
1 parent b756161 commit d3120b6

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

pkg/client/options.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ func (f FieldOwner) ApplyToUpdate(opts *UpdateOptions) {
154154
opts.FieldManager = string(f)
155155
}
156156

157+
// ApplyToSubResourcePatch applies this configuration to the given patch options.
158+
func (f FieldOwner) ApplyToSubResourcePatch(opts *SubResourcePatchOptions) {
159+
opts.FieldManager = string(f)
160+
}
161+
162+
// ApplyToSubResourceCreate applies this configuration to the given create options.
163+
func (f FieldOwner) ApplyToSubResourceCreate(opts *SubResourceCreateOptions) {
164+
opts.FieldManager = string(f)
165+
}
166+
167+
// ApplyToSubResourceUpdate applies this configuration to the given update options.
168+
func (f FieldOwner) ApplyToSubResourceUpdate(opts *SubResourceUpdateOptions) {
169+
opts.FieldManager = string(f)
170+
}
171+
157172
// }}}
158173

159174
// {{{ Create Options

pkg/client/options_test.go

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,27 @@ var _ = Describe("GetOptions", func() {
8686
var _ = Describe("CreateOptions", func() {
8787
It("Should set DryRun", func() {
8888
o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}}
89-
newCreatOpts := &client.CreateOptions{}
90-
o.ApplyToCreate(newCreatOpts)
91-
Expect(newCreatOpts).To(Equal(o))
89+
newCreateOpts := &client.CreateOptions{}
90+
o.ApplyToCreate(newCreateOpts)
91+
Expect(newCreateOpts).To(Equal(o))
9292
})
9393
It("Should set FieldManager", func() {
9494
o := &client.CreateOptions{FieldManager: "FieldManager"}
95-
newCreatOpts := &client.CreateOptions{}
96-
o.ApplyToCreate(newCreatOpts)
97-
Expect(newCreatOpts).To(Equal(o))
95+
newCreateOpts := &client.CreateOptions{}
96+
o.ApplyToCreate(newCreateOpts)
97+
Expect(newCreateOpts).To(Equal(o))
9898
})
9999
It("Should set Raw", func() {
100100
o := &client.CreateOptions{Raw: &metav1.CreateOptions{DryRun: []string{"Bye", "Theodore"}}}
101-
newCreatOpts := &client.CreateOptions{}
102-
o.ApplyToCreate(newCreatOpts)
103-
Expect(newCreatOpts).To(Equal(o))
101+
newCreateOpts := &client.CreateOptions{}
102+
o.ApplyToCreate(newCreateOpts)
103+
Expect(newCreateOpts).To(Equal(o))
104104
})
105105
It("Should not set anything", func() {
106106
o := &client.CreateOptions{}
107-
newCreatOpts := &client.CreateOptions{}
108-
o.ApplyToCreate(newCreatOpts)
109-
Expect(newCreatOpts).To(Equal(o))
107+
newCreateOpts := &client.CreateOptions{}
108+
o.ApplyToCreate(newCreateOpts)
109+
Expect(newCreateOpts).To(Equal(o))
110110
})
111111
})
112112

@@ -238,3 +238,42 @@ var _ = Describe("MatchingLabels", func() {
238238
Expect(err.Error()).To(Equal(expectedErrMsg))
239239
})
240240
})
241+
242+
var _ = Describe("FieldOwner", func() {
243+
It("Should apply to PatchOptions", func() {
244+
o := &client.PatchOptions{FieldManager: "bar"}
245+
t := client.FieldOwner("foo")
246+
t.ApplyToPatch(o)
247+
Expect(o.FieldManager).To(Equal("foo"))
248+
})
249+
It("Should apply to CreateOptions", func() {
250+
o := &client.CreateOptions{FieldManager: "bar"}
251+
t := client.FieldOwner("foo")
252+
t.ApplyToCreate(o)
253+
Expect(o.FieldManager).To(Equal("foo"))
254+
})
255+
It("Should apply to UpdateOptions", func() {
256+
o := &client.UpdateOptions{FieldManager: "bar"}
257+
t := client.FieldOwner("foo")
258+
t.ApplyToUpdate(o)
259+
Expect(o.FieldManager).To(Equal("foo"))
260+
})
261+
It("Should apply to SubResourcePatchOptions", func() {
262+
o := &client.SubResourcePatchOptions{PatchOptions: client.PatchOptions{FieldManager: "bar"}}
263+
t := client.FieldOwner("foo")
264+
t.ApplyToSubResourcePatch(o)
265+
Expect(o.FieldManager).To(Equal("foo"))
266+
})
267+
It("Should apply to SubResourceCreateOptions", func() {
268+
o := &client.SubResourceCreateOptions{CreateOptions: client.CreateOptions{FieldManager: "bar"}}
269+
t := client.FieldOwner("foo")
270+
t.ApplyToSubResourceCreate(o)
271+
Expect(o.FieldManager).To(Equal("foo"))
272+
})
273+
It("Should apply to SubResourceUpdateOptions", func() {
274+
o := &client.SubResourceUpdateOptions{UpdateOptions: client.UpdateOptions{FieldManager: "bar"}}
275+
t := client.FieldOwner("foo")
276+
t.ApplyToSubResourceUpdate(o)
277+
Expect(o.FieldManager).To(Equal("foo"))
278+
})
279+
})

0 commit comments

Comments
 (0)