mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 00:16:54 +00:00
Merge pull request #1396 from Liujingfang1/delete
support strategic merge patch with $patch: delete
This commit is contained in:
@@ -338,7 +338,11 @@ func (fs *UnstructAdapter) Patch(patch ifc.Kunstructured) error {
|
||||
}
|
||||
}
|
||||
fs.SetMap(merged)
|
||||
fs.SetName(saveName)
|
||||
if len(fs.Map()) != 0 {
|
||||
// if the patch deletes the object
|
||||
// don't reset the name
|
||||
fs.SetName(saveName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,14 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// remove the resource from resmap
|
||||
// when the patch is to $patch: delete that target
|
||||
if len(target.Map()) == 0 {
|
||||
err = m.Remove(target.CurId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,6 +71,14 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// remove the resource from resmap
|
||||
// when the patch is to $patch: delete that target
|
||||
if len(target.Map()) == 0 {
|
||||
err = m.Remove(target.CurId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1198,3 +1198,32 @@ func TestMultipleNamespaces(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatchStrategicMergeTransformerPatchDelete(t *testing.T) {
|
||||
tc := plugins_test.NewEnvForTest(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchStrategicMergeTransformer")
|
||||
|
||||
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
|
||||
|
||||
th.WriteF("/app/patch.yaml", `
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: myDeploy
|
||||
kind: Deployment
|
||||
$patch: delete
|
||||
`)
|
||||
|
||||
rm := th.LoadAndRunTransformer(`
|
||||
apiVersion: builtin
|
||||
kind: PatchStrategicMergeTransformer
|
||||
metadata:
|
||||
name: notImportantHere
|
||||
paths:
|
||||
- patch.yaml
|
||||
`, target)
|
||||
|
||||
th.AssertActualEqualsExpected(rm, ``)
|
||||
}
|
||||
Reference in New Issue
Block a user