Skip to content

Commit bc64d91

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 bc64d91

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/client/patch.go

Lines changed: 22 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,20 @@ 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+
return types.ApplyPatchType
86+
}
87+
88+
// Data implements Patch.
89+
func (p applyPatch) Data(obj runtime.Object) ([]byte, error) {
90+
// NB(directxman12): we might techically want to be using an actual encoder
91+
// here (in case some more performant encoder is introduced) but this is
92+
// correct and sufficient for our uses (it's what the JSON serializer in
93+
// client-go does, more-or-less).
94+
return json.Marshal(obj)
95+
}

0 commit comments

Comments
 (0)