From 3b504fa3e5cc741993a81b666e395dcd6ff2e242 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Mon, 2 Nov 2020 18:11:50 -0800 Subject: [PATCH 1/4] added StringList set --- .../patchstrategicmerge_test.go | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go index 867f83db6..6a7c3c9f8 100644 --- a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go +++ b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go @@ -370,6 +370,208 @@ spec: image: test2 - name: test image: test +`, + }, + // the following tests document broken behavior and + // will be fixed + // ref: #3111, #3159 + "list map keys - add a port, no names": { + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`, + patch: yaml.MustParse(` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 80 + protocol: UDP +`), + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 80 + protocol: UDP +`, + }, + "list map keys - add name to port": { + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 8080 + protocol: TCP +`, + patch: yaml.MustParse(` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: UDP-name-patch +`), + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`, + }, + "list map keys - replace port name": { + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: UDP-name-original + - containerPort: 8080 + protocol: TCP + name: TCP-name-original +`, + patch: yaml.MustParse(` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: UDP-name-patch +`), + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP + name: TCP-name-original +`, + }, + "list map keys - add a port, no protocol": { + input: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 +`, + patch: yaml.MustParse(` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 +`), + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + - containerPort: 8080 `, }, } From 9943e741875fdfe05a1055ddce6f86924aa36296 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Wed, 4 Nov 2020 10:58:20 -0800 Subject: [PATCH 2/4] updated comments --- api/filters/patchstrategicmerge/patchstrategicmerge_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go index 6a7c3c9f8..6c69968c7 100644 --- a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go +++ b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go @@ -529,6 +529,10 @@ spec: name: TCP-name-original `, }, + + // the following tests document behavior + // that should not be affected by + // changes due to #3111, #3159 "list map keys - add a port, no protocol": { input: ` apiVersion: apps/v1 From 3923c63182f3cf01dc74e48076f5a825db1befa0 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Wed, 4 Nov 2020 11:31:48 -0800 Subject: [PATCH 3/4] added some tests to merge3/element_test.go --- kyaml/yaml/merge3/element_test.go | 347 ++++++++++++++++++++++++++++++ 1 file changed, 347 insertions(+) diff --git a/kyaml/yaml/merge3/element_test.go b/kyaml/yaml/merge3/element_test.go index 9b685c1c8..09ea90c8f 100644 --- a/kyaml/yaml/merge3/element_test.go +++ b/kyaml/yaml/merge3/element_test.go @@ -917,4 +917,351 @@ spec: `, infer: false, }, + + // The following test cases are regression tests + // that should not be broken as a result of + // #3111, #3159 + + // + // Test Case + // + { + description: `Add a containerPort to an existing list`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + - containerPort: 80 +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + - containerPort: 80 +`}, + + // + // Test Case + // + { + description: `Add a containerPort to a non-existing list, existing in dest`, + origin: ` +apiVersion: apps/v1 +kind: Deployment`, + update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + - containerPort: 8080 +`}, + + // + // Test Case + // + { + description: `Add a name to containerPort`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + name: 8080-port-update + - containerPort: 80 +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + - containerPort: 80 +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + name: 8080-port-update + - containerPort: 80 +`}, + + // The following test cases document broken behavior + // that will change as a result of #3111, #3159 + + // + // Test Case + // +{ + description: `Add a containerPort with protocol to an existing list`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 80 + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 80 + protocol: TCP +`}, + +// +// Test Case +// +{ +description: `Add a containerPort with protocol to a non-existing list, existing in dest`, +origin: ` +apiVersion: apps/v1 +kind: Deployment`, +update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, +local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + protocol: TCP +`, +expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + protocol: TCP + - containerPort: 8080 + protocol: UDP +`}, + +// +// Test Case +// +{ +description: `Add a name to containerPort with protocol`, +origin: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + protocol: TCP +`, +update: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: 8080-port-update + - containerPort: 80 + protocol: TCP +`, +local: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + - containerPort: 80 + protocol: TCP +`, +expected: ` +apiVersion: apps/v1 +kind: Deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: 8080-port-update + - containerPort: 80 + protocol: TCP +`}, + } From c0ecd1d1ad58c3fd845eb4423af19cc4a1498a99 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Wed, 4 Nov 2020 19:07:53 -0800 Subject: [PATCH 4/4] added more tests --- kyaml/yaml/merge3/element_test.go | 418 ++++++++++++++++++++++++------ 1 file changed, 344 insertions(+), 74 deletions(-) diff --git a/kyaml/yaml/merge3/element_test.go b/kyaml/yaml/merge3/element_test.go index 09ea90c8f..ca1626f30 100644 --- a/kyaml/yaml/merge3/element_test.go +++ b/kyaml/yaml/merge3/element_test.go @@ -1039,7 +1039,7 @@ spec: - image: test-image name: test-deployment ports: - - containerPort: 80 + - containerPort: 8080 `, update: ` apiVersion: apps/v1 @@ -1082,6 +1082,205 @@ spec: name: 8080-port-update - containerPort: 80 `}, + // + // Test Case + // + { + description: `Update protocol for a port`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`}, + // + // Test Case + // + { + description: `Append container port`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + protocol: HTTP +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 80 + protocol: HTTP + - protocol: TCP + containerPort: 8080 +`}, + + { + description: `Update container-port name`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: foo +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP + name: bar +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP + name: foo +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP + name: bar +`}, // The following test cases document broken behavior // that will change as a result of #3111, #3159 @@ -1116,7 +1315,7 @@ spec: ports: - containerPort: 8080 protocol: UDP - - containerPort: 80 + - containerPort: 8080 protocol: TCP `, local: ` @@ -1131,7 +1330,7 @@ spec: ports: - containerPort: 8080 protocol: UDP -`, +`, // output should have both expected: ` apiVersion: apps/v1 kind: Deployment @@ -1144,8 +1343,6 @@ spec: ports: - containerPort: 8080 protocol: UDP - - containerPort: 80 - protocol: TCP `}, // @@ -1179,74 +1376,9 @@ spec: - image: test-image name: test-deployment ports: - - containerPort: 80 - protocol: TCP -`, -expected: ` -apiVersion: apps/v1 -kind: Deployment -spec: - template: - spec: - containers: - - image: test-image - name: test-deployment - ports: - - containerPort: 80 - protocol: TCP - containerPort: 8080 - protocol: UDP -`}, - -// -// Test Case -// -{ -description: `Add a name to containerPort with protocol`, -origin: ` -apiVersion: apps/v1 -kind: Deployment -spec: - template: - spec: - containers: - - image: test-image - name: test-deployment - ports: - - containerPort: 80 protocol: TCP -`, -update: ` -apiVersion: apps/v1 -kind: Deployment -spec: - template: - spec: - containers: - - image: test-image - name: test-deployment - ports: - - containerPort: 8080 - protocol: UDP - name: 8080-port-update - - containerPort: 80 - protocol: TCP -`, -local: ` -apiVersion: apps/v1 -kind: Deployment -spec: - template: - spec: - containers: - - image: test-image - name: test-deployment - ports: - - containerPort: 8080 - protocol: UDP - - containerPort: 80 - protocol: TCP -`, +`, // output should have both expected: ` apiVersion: apps/v1 kind: Deployment @@ -1259,9 +1391,147 @@ spec: ports: - containerPort: 8080 protocol: UDP - name: 8080-port-update - - containerPort: 80 - protocol: TCP `}, + // + // Test Case + // + { + description: `Merge with name for same container-port`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: original +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: original + - containerPort: 8080 + protocol: TCP + name: updated +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: original + - containerPort: 8080 + protocol: HTTP + name: local +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP + name: original + - containerPort: 8080 + protocol: UDP + name: original +`}, + + { + description: `Retain local protocol`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: UDP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: HTTP +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8080 + protocol: TCP +`}, }