Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add additional SubResource* functions for FieldOwner #2115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Since I couldn't find any tests for FieldOwner, I wrote some from scratch. I hope they're to your taste.

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
Expand Down
63 changes: 51 additions & 12 deletions pkg/client/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

Expand Down Expand Up @@ -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"))
})
})