Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't panic on multiple $patch: delete strategic merge patches in a single patch file #5859

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions api/krusty/multiplepatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,58 @@ 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
`)
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)
Expand Down
4 changes: 4 additions & 0 deletions api/resmap/reswrangler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading