mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
fix: Don't panic on multiple $patch: delete strategic merge patches in a single patch file (#5859)
* chore: add test for multiple $patch: delete patches not panicking * fix: don't panic on multiple deletion SM patches
This commit is contained in:
@@ -1282,6 +1282,72 @@ metadata:
|
||||
}
|
||||
}
|
||||
|
||||
func TestSinglePatchWithMultiplePatchDeleteDirectives(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
makeCommonFilesForMultiplePatchTests(th)
|
||||
th.WriteF("overlay/staging/deployment-patch1.yaml", `
|
||||
$patch: delete
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
---
|
||||
$patch: delete
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
`)
|
||||
th.WriteF("overlay/staging/deployment-patch2.yaml", `
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: configmap-in-base
|
||||
data:
|
||||
foo2: bar2
|
||||
`)
|
||||
th.WriteK("overlay/staging", `
|
||||
namePrefix: staging-
|
||||
commonLabels:
|
||||
env: staging
|
||||
patches:
|
||||
- path: deployment-patch1.yaml
|
||||
- path: deployment-patch2.yaml
|
||||
resources:
|
||||
- ../../base
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
`)
|
||||
m := th.Run("overlay/staging", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
data:
|
||||
foo: bar
|
||||
foo2: bar2
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mynginx
|
||||
env: staging
|
||||
org: example.com
|
||||
team: foo
|
||||
name: staging-team-foo-configmap-in-base-8cmgkm9f44
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
hello: world
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
labels:
|
||||
env: staging
|
||||
name: staging-configmap-in-overlay-dc6fm46dhm
|
||||
`)
|
||||
}
|
||||
|
||||
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
makeCommonFilesForMultiplePatchTests(th)
|
||||
|
||||
@@ -181,6 +181,10 @@ func (m *resWrangler) GetMatchingResourcesByAnyId(
|
||||
matches IdMatcher) []*resource.Resource {
|
||||
var result []*resource.Resource
|
||||
for _, r := range m.rList {
|
||||
if r.RNode.IsNilOrEmpty() {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, id := range append(r.PrevIds(), r.CurId()) {
|
||||
if matches(id) {
|
||||
result = append(result, r)
|
||||
|
||||
Reference in New Issue
Block a user