From 57a53797d3c433d263496742e7416af84aa63bca Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Fri, 29 Jan 2021 11:10:00 -0800 Subject: [PATCH] Add test for ports issue #3513 --- .../patchstrategicmerge_test.go | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go index cca621090..82d427e98 100644 --- a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go +++ b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go @@ -672,6 +672,63 @@ spec: ports: - containerPort: 80 - containerPort: 8080 +`, + }, + + // Test for issue #3513 + // Currently broken; when one port has only containerPort, the output + // should not merge containerPort 8301 together + // This occurs because when protocol is missing on the first port, + // the merge code uses [containerPort] as the merge key rather than + // [containerPort, protocol] + "list map keys - protocol only present on some ports": { + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - name: consul + image: "hashicorp/consul:1.9.1" + ports: + - containerPort: 8500 + name: http + - containerPort: 8301 + protocol: "TCP" + - containerPort: 8301 + protocol: "UDP" +`, + patch: yaml.MustParse(` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment + labels: + test: label +`), + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment + labels: + test: label +spec: + template: + spec: + containers: + - name: consul + image: "hashicorp/consul:1.9.1" + ports: + - containerPort: 8500 + name: http + - containerPort: 8301 + protocol: "UDP" + - containerPort: 8301 + protocol: "UDP" `, }, }