Skip to content

Commit 1373e0e

Browse files
committed
topology: use raw input object for patch calculation in WalkTemplates
1 parent ad97dc5 commit 1373e0e

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

exp/runtime/topologymutation/walker.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ func WalkTemplates(ctx context.Context, decoder runtime.Decoder, req *runtimehoo
147147
var patch []byte
148148
switch options.patchFormat {
149149
case runtimehooksv1.JSONPatchType:
150-
patch, err = createJSONPatch(original, modified)
150+
patch, err = createJSONPatch(requestItem.Object.Raw, modified)
151151
if err != nil {
152152
resp.Status = runtimehooksv1.ResponseStatusFailure
153153
resp.Message = err.Error()
154154
return
155155
}
156156
case runtimehooksv1.JSONMergePatchType:
157-
patch, err = createJSONMergePatch(original, modified)
157+
patch, err = createJSONMergePatch(requestItem.Object.Raw, modified)
158158
if err != nil {
159159
resp.Status = runtimehooksv1.ResponseStatusFailure
160160
resp.Message = err.Error()
@@ -174,12 +174,7 @@ func WalkTemplates(ctx context.Context, decoder runtime.Decoder, req *runtimehoo
174174
}
175175

176176
// createJSONPatch creates a RFC 6902 JSON patch from the original and the modified object.
177-
func createJSONPatch(original, modified runtime.Object) ([]byte, error) {
178-
marshalledOriginal, err := json.Marshal(original)
179-
if err != nil {
180-
return nil, errors.Errorf("failed to marshal original object: %v", err)
181-
}
182-
177+
func createJSONPatch(marshalledOriginal []byte, modified runtime.Object) ([]byte, error) {
183178
marshalledModified, err := json.Marshal(modified)
184179
if err != nil {
185180
return nil, errors.Errorf("failed to marshal modified object: %v", err)
@@ -199,12 +194,7 @@ func createJSONPatch(original, modified runtime.Object) ([]byte, error) {
199194
}
200195

201196
// createJSONMergePatch creates a RFC 7396 JSON merge patch from the original and the modified object.
202-
func createJSONMergePatch(original, modified runtime.Object) ([]byte, error) {
203-
marshalledOriginal, err := json.Marshal(original)
204-
if err != nil {
205-
return nil, errors.Errorf("failed to marshal original object: %v", err)
206-
}
207-
197+
func createJSONMergePatch(marshalledOriginal []byte, modified runtime.Object) ([]byte, error) {
208198
marshalledModified, err := json.Marshal(modified)
209199
if err != nil {
210200
return nil, errors.Errorf("failed to marshal modified object: %v", err)

0 commit comments

Comments
 (0)