Skip to content

Commit a03a8c2

Browse files
committed
Server Side Apply Patch Type
This introduces a patch type for server-side apply, and the associated patch options.
1 parent 2915b92 commit a03a8c2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/client/patch.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import (
2323
"k8s.io/apimachinery/pkg/util/strategicpatch"
2424
)
2525

26+
var (
27+
// Apply uses server-side apply to patch the given object.
28+
Apply = applyPatch{}
29+
)
30+
2631
type patch struct {
2732
patchType types.PatchType
2833
data []byte
@@ -72,3 +77,21 @@ func (s *mergeFromPatch) Data(obj runtime.Object) ([]byte, error) {
7277
func MergeFrom(obj runtime.Object) Patch {
7378
return &mergeFromPatch{obj}
7479
}
80+
81+
// applyPatch uses server-side apply to patch the object.
82+
type applyPatch struct{}
83+
84+
// Type implements Patch.
85+
func (p applyPatch) Type() types.PatchType {
86+
// TODO(directxman12): when we update to 1.14, just use types.ApplyPatch
87+
return "application/apply-patch+yaml"
88+
}
89+
90+
// Data implements Patch.
91+
func (p applyPatch) Data(obj runtime.Object) ([]byte, error) {
92+
// NB(directxman12): we might techically want to be using an actual encoder
93+
// here (in case some more performant encoder is introduced) but this is
94+
// correct and sufficient for our uses (it's what the JSON serializer in
95+
// client-go does, more-or-less).
96+
return json.Marshal(obj)
97+
}

0 commit comments

Comments
 (0)