Skip to content

Commit 90aea15

Browse files
committed
✨ PatchOptions implement PatchOpts
1 parent aafb998 commit 90aea15

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

pkg/client/options.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,24 @@ func (o *PatchOptions) AsPatchOptions() *metav1.PatchOptions {
518518
return o.Raw
519519
}
520520

521+
var _ PatchOption = &PatchOptions{}
522+
523+
// ApplyToPatch implements PatchOptions
524+
func (o *PatchOptions) ApplyToPatch(po *PatchOptions) {
525+
if o.DryRun != nil {
526+
po.DryRun = o.DryRun
527+
}
528+
if o.Force != nil {
529+
po.Force = o.Force
530+
}
531+
if o.FieldManager != "" {
532+
po.FieldManager = o.FieldManager
533+
}
534+
if o.Raw != nil {
535+
po.Raw = o.Raw
536+
}
537+
}
538+
521539
// ForceOwnership indicates that in case of conflicts with server-side apply,
522540
// the client should acquire ownership of the conflicting field. Most
523541
// controllers should use this.

pkg/client/options_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,36 @@ var _ = Describe("UpdateOptions", func() {
155155
Expect(newUpdateOpts).To(Equal(o))
156156
})
157157
})
158+
159+
var _ = Describe("PatchOptions", func() {
160+
It("Should set DryRun", func() {
161+
o := &client.PatchOptions{DryRun: []string{"Bye", "Boris"}}
162+
newPatchOpts := &client.PatchOptions{}
163+
o.ApplyToPatch(newPatchOpts)
164+
Expect(newPatchOpts).To(Equal(o))
165+
})
166+
It("Should set Force", func() {
167+
o := &client.PatchOptions{Force: utilpointer.BoolPtr(true)}
168+
newPatchOpts := &client.PatchOptions{}
169+
o.ApplyToPatch(newPatchOpts)
170+
Expect(newPatchOpts).To(Equal(o))
171+
})
172+
It("Should set FieldManager", func() {
173+
o := &client.PatchOptions{FieldManager: "Hello Julian"}
174+
newPatchOpts := &client.PatchOptions{}
175+
o.ApplyToPatch(newPatchOpts)
176+
Expect(newPatchOpts).To(Equal(o))
177+
})
178+
It("Should set Raw", func() {
179+
o := &client.PatchOptions{Raw: &metav1.PatchOptions{}}
180+
newPatchOpts := &client.PatchOptions{}
181+
o.ApplyToPatch(newPatchOpts)
182+
Expect(newPatchOpts).To(Equal(o))
183+
})
184+
It("Should not set anything", func() {
185+
o := &client.PatchOptions{}
186+
newPatchOpts := &client.PatchOptions{}
187+
o.ApplyToPatch(newPatchOpts)
188+
Expect(newPatchOpts).To(Equal(o))
189+
})
190+
})

0 commit comments

Comments
 (0)