Skip to content

Commit

Permalink
✨ PatchOptions implement PatchOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Sep 9, 2019
1 parent ccdcbc7 commit 1e8c57f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,24 @@ func (o *PatchOptions) AsPatchOptions() *metav1.PatchOptions {
return o.Raw
}

var _ PatchOption = &PatchOptions{}

// ApplyToPatch implements PatchOptions
func (o *PatchOptions) ApplyToPatch(po *PatchOptions) {
if o.DryRun != nil {
po.DryRun = o.DryRun
}
if o.Force != nil {
po.Force = o.Force
}
if o.FieldManager != "" {
po.FieldManager = o.FieldManager
}
if o.Raw != nil {
po.Raw = o.Raw
}
}

// ForceOwnership indicates that in case of conflicts with server-side apply,
// the client should acquire ownership of the conflicting field. Most
// controllers should use this.
Expand Down
33 changes: 33 additions & 0 deletions pkg/client/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,36 @@ var _ = Describe("UpdateOptions", func() {
Expect(newUpdateOpts).To(Equal(o))
})
})

var _ = Describe("PatchOptions", func() {
It("Should set DryRun", func() {
o := &client.PatchOptions{DryRun: []string{"Bye", "Boris"}}
newPatchOpts := &client.PatchOptions{}
o.ApplyToPatch(newPatchOpts)
Expect(newPatchOpts).To(Equal(o))
})
It("Should set Force", func() {
o := &client.PatchOptions{Force: utilpointer.BoolPtr(true)}
newPatchOpts := &client.PatchOptions{}
o.ApplyToPatch(newPatchOpts)
Expect(newPatchOpts).To(Equal(o))
})
It("Should set FieldManager", func() {
o := &client.PatchOptions{FieldManager: "Hello Julian"}
newPatchOpts := &client.PatchOptions{}
o.ApplyToPatch(newPatchOpts)
Expect(newPatchOpts).To(Equal(o))
})
It("Should set Raw", func() {
o := &client.PatchOptions{Raw: &metav1.PatchOptions{}}
newPatchOpts := &client.PatchOptions{}
o.ApplyToPatch(newPatchOpts)
Expect(newPatchOpts).To(Equal(o))
})
It("Should not set anything", func() {
o := &client.PatchOptions{}
newPatchOpts := &client.PatchOptions{}
o.ApplyToPatch(newPatchOpts)
Expect(newPatchOpts).To(Equal(o))
})
})

0 comments on commit 1e8c57f

Please sign in to comment.