mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
add inline patch support for Strategic Merge Patch and JSON patch
This commit is contained in:
@@ -35,11 +35,18 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
||||
return fmt.Errorf("empty file path and empty patch content")
|
||||
}
|
||||
if len(p.Paths) != 0 {
|
||||
res, err := p.rf.RF().SliceFromPatches(ldr, p.Paths)
|
||||
if err != nil {
|
||||
return err
|
||||
for _, onePath := range p.Paths {
|
||||
res, err := p.rf.RF().SliceFromBytes([]byte(onePath))
|
||||
if err == nil {
|
||||
p.loadedPatches = append(p.loadedPatches, res...)
|
||||
continue
|
||||
}
|
||||
res, err = p.rf.RF().SliceFromPatches(ldr, []types.PatchStrategicMerge{onePath})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.loadedPatches = append(p.loadedPatches, res...)
|
||||
}
|
||||
p.loadedPatches = res
|
||||
}
|
||||
if p.Patches != "" {
|
||||
res, err := p.rf.RF().SliceFromBytes([]byte(p.Patches))
|
||||
|
||||
@@ -36,11 +36,18 @@ func (p *plugin) Config(
|
||||
return fmt.Errorf("empty file path and empty patch content")
|
||||
}
|
||||
if len(p.Paths) != 0 {
|
||||
res, err := p.rf.RF().SliceFromPatches(ldr, p.Paths)
|
||||
if err != nil {
|
||||
return err
|
||||
for _, onePath := range p.Paths {
|
||||
res, err := p.rf.RF().SliceFromBytes([]byte(onePath))
|
||||
if err == nil {
|
||||
p.loadedPatches = append(p.loadedPatches, res...)
|
||||
continue
|
||||
}
|
||||
res, err = p.rf.RF().SliceFromPatches(ldr, []types.PatchStrategicMerge{onePath})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.loadedPatches = append(p.loadedPatches, res...)
|
||||
}
|
||||
p.loadedPatches = res
|
||||
}
|
||||
if p.Patches != "" {
|
||||
res, err := p.rf.RF().SliceFromBytes([]byte(p.Patches))
|
||||
|
||||
@@ -78,7 +78,9 @@ paths:
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(),
|
||||
"cannot read file \"/app/patch.yaml\"") {
|
||||
"cannot read file \"/app/patch.yaml\"") &&
|
||||
!strings.Contains(err.Error(),
|
||||
"cannot unmarshal string") {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1278,4 +1280,4 @@ paths:
|
||||
`, target)
|
||||
|
||||
th.AssertActualEqualsExpected(rm, ``)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user