Skip to content

Commit 932da30

Browse files
authored
fix: json patch allows empty path on add and remove (#1274)
1 parent 7566683 commit 932da30

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/modules/generators/app_configurations_generator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ func JSONPatch(resources v1.Resources, patcher *v1.Patcher) error {
232232
return fmt.Errorf("decode json patch:%s failed with error %w", jsonPatcher.Payload, err)
233233
}
234234

235-
modified, err := patch.Apply([]byte(target))
235+
// Apply JSON Patch with options to allow missing path on `remove`,
236+
// and ensure path exists on `add`.
237+
applyOpts := jsonpatch.NewApplyOptions()
238+
applyOpts.AllowMissingPathOnRemove = true
239+
applyOpts.EnsurePathExistsOnAdd = true
240+
241+
modified, err := patch.ApplyWithOptions([]byte(target), applyOpts)
236242
if err != nil {
237243
return fmt.Errorf("apply json patch to:%s failed with error %w", id, err)
238244
}

0 commit comments

Comments
 (0)