Skip to content

Commit 06c2f65

Browse files
committed
Server Side Apply Patch Type
This introduces a patch type for server-side apply, and the associated patch options.
1 parent 3511f3c commit 06c2f65

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/json"
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
@@ -71,3 +76,21 @@ func (s *mergeFromPatch) Data(obj runtime.Object) ([]byte, error) {
7176
func MergeFrom(obj runtime.Object) Patch {
7277
return &mergeFromPatch{obj}
7378
}
79+
80+
// applyPatch uses server-side apply to patch the object.
81+
type applyPatch struct{}
82+
83+
// Type implements Patch.
84+
func (p applyPatch) Type() types.PatchType {
85+
// TODO(directxman12): when we update to 1.14, just use types.ApplyPatch
86+
return "application/apply-patch+yaml"
87+
}
88+
89+
// Data implements Patch.
90+
func (p applyPatch) Data(obj runtime.Object) ([]byte, error) {
91+
// NB(directxman12): we might techically want to be using an actual encoder
92+
// here (in case some more performant encoder is introduced) but this is
93+
// correct and sufficient for our uses (it's what the JSON serializer in
94+
// client-go does, more-or-less).
95+
return json.Marshal(obj)
96+
}

0 commit comments

Comments
 (0)