mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 18:10:59 +00:00
Merge pull request #3506 from natasha41575/FixSmpDirectiveWhenElementNotFound
$patch:delete should not add elements when element is not found
This commit is contained in:
@@ -60,11 +60,10 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
|||||||
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
||||||
}
|
}
|
||||||
// Merge the patches, looking for conflicts.
|
// Merge the patches, looking for conflicts.
|
||||||
m, err := h.ResmapFactory().ConflatePatches(p.loadedPatches)
|
_, err = h.ResmapFactory().ConflatePatches(p.loadedPatches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.loadedPatches = m.Resources()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,28 +69,6 @@ spec:
|
|||||||
image: helloworld
|
image: helloworld
|
||||||
name: whatever
|
name: whatever
|
||||||
`
|
`
|
||||||
// Allow expected variable to be unused
|
|
||||||
_ = expected
|
|
||||||
|
|
||||||
// Currently, kustomize inserts $patch: delete elements into the resulting resources
|
|
||||||
erroneousActual := `
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: whatever
|
|
||||||
spec:
|
|
||||||
template:
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- env:
|
|
||||||
- $patch: delete
|
|
||||||
name: NOT_EXISTING_FOR_REMOVAL
|
|
||||||
- name: EXISTING
|
|
||||||
value: EXISTING_VALUE
|
|
||||||
image: helloworld
|
|
||||||
name: whatever
|
|
||||||
`
|
|
||||||
|
|
||||||
m := th.Run(".", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, erroneousActual)
|
th.AssertActualEqualsExpected(m, expected)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ func (m Merger) VisitMap(nodes walk.Sources, s *openapi.ResourceSchema) (*yaml.R
|
|||||||
}
|
}
|
||||||
if yaml.IsMissingOrNull(nodes.Dest()) {
|
if yaml.IsMissingOrNull(nodes.Dest()) {
|
||||||
// Add
|
// Add
|
||||||
|
ps, _ := determineSmpDirective(nodes.Origin())
|
||||||
|
if ps == smpDelete {
|
||||||
|
return walk.ClearNode, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nodes.Origin(), nil
|
return nodes.Origin(), nil
|
||||||
}
|
}
|
||||||
if nodes.Origin().IsTaggedNull() {
|
if nodes.Origin().IsTaggedNull() {
|
||||||
|
|||||||
@@ -64,11 +64,10 @@ func (p *plugin) Config(
|
|||||||
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
||||||
}
|
}
|
||||||
// Merge the patches, looking for conflicts.
|
// Merge the patches, looking for conflicts.
|
||||||
m, err := h.ResmapFactory().ConflatePatches(p.loadedPatches)
|
_, err = h.ResmapFactory().ConflatePatches(p.loadedPatches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.loadedPatches = m.Resources()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user