Skip to content

Commit

Permalink
add from field and enhance coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com>
  • Loading branch information
Anshul Ahuja committed Jul 13, 2023
1 parent 7396e64 commit f156a2c
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 26 deletions.
6 changes: 5 additions & 1 deletion internal/resourcemodifiers/resource_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (

type JSONPatch struct {
Operation string `yaml:"operation"`
From string `yaml:"from,omitempty"`
Path string `yaml:"path"`
Value string `yaml:"value,omitempty"`
}
Expand Down Expand Up @@ -116,7 +117,10 @@ func (r *ResourceModifierRule) PatchArrayToByteArray() ([]byte, error) {
}

func (p *JSONPatch) ToString() string {
return fmt.Sprintf(`{"op": "%s", "path": "%s", "value": "%s"}`, p.Operation, p.Path, p.Value)
if strings.Contains(p.Value, "\"") {
return fmt.Sprintf(`{"op": "%s", "from": "%s", "path": "%s", "value": %s}`, p.Operation, p.From, p.Path, p.Value)
}
return fmt.Sprintf(`{"op": "%s", "from": "%s", "path": "%s", "value": "%s"}`, p.Operation, p.From, p.Path, p.Value)
}

func ApplyPatch(patch []byte, obj *unstructured.Unstructured, log logrus.FieldLogger) error {
Expand Down
Loading

0 comments on commit f156a2c

Please sign in to comment.