From 95203c58c4ffa9bb8b847eabb4054340e957e0ce Mon Sep 17 00:00:00 2001 From: jregan Date: Fri, 28 Dec 2018 07:35:29 -0800 Subject: [PATCH] Convert multi-patch test to in-memory. --- pkg/commands/build/build_test.go | 5 - .../in/overlay/deployment-patch1.yaml | 20 -- .../in/overlay/deployment-patch2.yaml | 12 - .../in/overlay/kustomization.yaml | 14 - .../in/package/deployment.yaml | 24 -- .../in/package/kustomization.yaml | 16 - .../in/package/service.yaml | 11 - .../test.yaml | 4 - .../expected.diff | 99 ------ .../expected.yaml | 94 ------ .../in/overlay/kustomization.yaml | 14 - .../in/overlay/patches/deployment-patch1.yaml | 21 -- .../in/overlay/patches/deployment-patch2.yaml | 16 - .../in/package/deployment.yaml | 24 -- .../in/package/kustomization.yaml | 16 - .../in/package/service.yaml | 11 - .../test.yaml | 5 - pkg/target/multiplepatch_test.go | 293 ++++++++++++++++++ pkg/target/utils_for_test.go | 3 + 19 files changed, 296 insertions(+), 406 deletions(-) delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml delete mode 100644 pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml create mode 100644 pkg/target/multiplepatch_test.go diff --git a/pkg/commands/build/build_test.go b/pkg/commands/build/build_test.go index ead4f6556..df332b73b 100644 --- a/pkg/commands/build/build_test.go +++ b/pkg/commands/build/build_test.go @@ -27,7 +27,6 @@ import ( "github.com/ghodss/yaml" "sigs.k8s.io/kustomize/k8sdeps" - "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -98,10 +97,6 @@ func TestBuild(t *testing.T) { } return nil }) - // sanity check that we found the right folder - if !kustfile.StringInSlice("multiple-patches-noconflict", testcases) { - t.Fatalf("Error locating testcases") - } for _, testcaseName := range testcases { t.Run(testcaseName, func(t *testing.T) { diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml deleted file mode 100644 index c92c5090e..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - template: - spec: - containers: - - name: nginx - env: - - name: ENABLE_FEATURE_FOO - value: TRUE - volumes: - - name: nginx-persistent-storage - emptyDir: null - gcePersistentDisk: - pdName: nginx-persistent-storage - - configMap: - name: configmap-in-overlay - name: configmap-in-overlay diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml deleted file mode 100644 index ab0bffbdf..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - template: - spec: - containers: - - name: nginx - env: - - name: ENABLE_FEATURE_FOO - value: FALSE diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml deleted file mode 100644 index f153f0692..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1beta1 -kind: Kustomization -namePrefix: staging- -commonLabels: - env: staging -patchesStrategicMerge: - - deployment-patch2.yaml - - deployment-patch1.yaml -bases: - - ../package/ -configMapGenerator: - - name: configmap-in-overlay - literals: - - hello=world diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml deleted file mode 100644 index 9f7d3cbb6..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx - labels: - app: nginx -spec: - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: nginx - volumeMounts: - - name: nginx-persistent-storage - mountPath: /tmp/ps - volumes: - - name: nginx-persistent-storage - emptyDir: {} - - configMap: - name: configmap-in-base - name: configmap-in-base diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml deleted file mode 100644 index 34b6d11b3..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1beta1 -kind: Kustomization -namePrefix: team-foo- -commonLabels: - app: mynginx - org: example.com - team: foo -commonAnnotations: - note: This is a test annotation -resources: - - deployment.yaml - - service.yaml -configMapGenerator: - - name: configmap-in-base - literals: - - foo=bar diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml deleted file mode 100644 index f6dd86909..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: nginx - labels: - app: nginx -spec: - ports: - - port: 80 - selector: - app: nginx diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml deleted file mode 100644 index a92e7f92d..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml +++ /dev/null @@ -1,4 +0,0 @@ -description: conflict between multiple patches -args: [] -filename: testdata/testcase-multiple-patches-conflict/in/overlay/ -expectedError: conflict diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff deleted file mode 100644 index c957e263b..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff +++ /dev/null @@ -1,99 +0,0 @@ -diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml ---- /tmp/noop/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/apps_v1beta2_Deployment_nginx.yaml YYYY-MM-DD HH:MM:SS -@@ -5,13 +5,15 @@ - note: This is a test annotation - labels: - app: mynginx -+ env: staging - org: example.com - team: foo -- name: team-foo-nginx -+ name: staging-team-foo-nginx - spec: - selector: - matchLabels: - app: mynginx -+ env: staging - org: example.com - team: foo - template: -@@ -20,18 +22,30 @@ - note: This is a test annotation - labels: - app: mynginx -+ env: staging - org: example.com - team: foo - spec: - containers: -- - image: nginx -+ - env: -+ - name: ANOTHERENV -+ value: FOO -+ - name: ENVKEY -+ value: ENVVALUE -+ image: nginx:latest - name: nginx - volumeMounts: - - mountPath: /tmp/ps - name: nginx-persistent-storage -+ - image: sidecar -+ name: sidecar - volumes: -- - emptyDir: {} -+ - gcePersistentDisk: -+ pdName: nginx-persistent-storage - name: nginx-persistent-storage - - configMap: -- name: team-foo-configmap-in-base-bbdmdh7m8t -+ name: staging-configmap-in-overlay-k7cbc75tg8 -+ name: configmap-in-overlay -+ - configMap: -+ name: staging-team-foo-configmap-in-base-g7k6gt2889 - name: configmap-in-base -diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-base.yaml /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml ---- /tmp/noop/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS -@@ -8,6 +8,7 @@ - creationTimestamp: null - labels: - app: mynginx -+ env: staging - org: example.com - team: foo -- name: team-foo-configmap-in-base-bbdmdh7m8t -+ name: staging-team-foo-configmap-in-base-g7k6gt2889 -diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml ---- /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS -@@ -0,0 +1,9 @@ -+apiVersion: v1 -+data: -+ hello: world -+kind: ConfigMap -+metadata: -+ creationTimestamp: null -+ labels: -+ env: staging -+ name: staging-configmap-in-overlay-k7cbc75tg8 -diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml ---- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS -@@ -5,13 +5,15 @@ - note: This is a test annotation - labels: - app: mynginx -+ env: staging - org: example.com - team: foo -- name: team-foo-nginx -+ name: staging-team-foo-nginx - spec: - ports: - - port: 80 - selector: - app: mynginx -+ env: staging - org: example.com - team: foo diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml deleted file mode 100644 index 2404ec1c9..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml +++ /dev/null @@ -1,94 +0,0 @@ -apiVersion: v1 -data: - foo: bar -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-g7k6gt2889 ---- -apiVersion: v1 -data: - hello: world -kind: ConfigMap -metadata: - labels: - env: staging - name: staging-configmap-in-overlay-k7cbc75tg8 ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: foo - name: staging-team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - env: staging - org: example.com - team: foo ---- -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: foo - name: staging-team-foo-nginx -spec: - selector: - matchLabels: - app: mynginx - env: staging - org: example.com - team: foo - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: foo - spec: - containers: - - env: - - name: ANOTHERENV - value: FOO - - name: ENVKEY - value: ENVVALUE - image: nginx:latest - name: nginx - volumeMounts: - - mountPath: /tmp/ps - name: nginx-persistent-storage - - image: sidecar - name: sidecar - volumes: - - gcePersistentDisk: - pdName: nginx-persistent-storage - name: nginx-persistent-storage - - configMap: - name: staging-configmap-in-overlay-k7cbc75tg8 - name: configmap-in-overlay - - configMap: - name: staging-team-foo-configmap-in-base-g7k6gt2889 - name: configmap-in-base diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml deleted file mode 100644 index 4fb0c9391..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1beta1 -kind: Kustomization -namePrefix: staging- -commonLabels: - env: staging -patchesStrategicMerge: - - patches/deployment-patch1.yaml - - patches/deployment-patch2.yaml -bases: - - ../package/ -configMapGenerator: - - name: configmap-in-overlay - literals: - - hello=world diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml deleted file mode 100644 index 444e05b22..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - template: - spec: - containers: - - name: nginx - image: nginx:latest - env: - - name: ENVKEY - value: ENVVALUE - volumes: - - name: nginx-persistent-storage - emptyDir: null - gcePersistentDisk: - pdName: nginx-persistent-storage - - configMap: - name: configmap-in-overlay - name: configmap-in-overlay diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml deleted file mode 100644 index f4006d1c7..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - template: - spec: - containers: - - name: nginx - env: - - name: ANOTHERENV - value: FOO - - name: sidecar - image: sidecar - volumes: - - name: nginx-persistent-storage diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml deleted file mode 100644 index 9f7d3cbb6..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx - labels: - app: nginx -spec: - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: nginx - volumeMounts: - - name: nginx-persistent-storage - mountPath: /tmp/ps - volumes: - - name: nginx-persistent-storage - emptyDir: {} - - configMap: - name: configmap-in-base - name: configmap-in-base diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml deleted file mode 100644 index 34b6d11b3..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1beta1 -kind: Kustomization -namePrefix: team-foo- -commonLabels: - app: mynginx - org: example.com - team: foo -commonAnnotations: - note: This is a test annotation -resources: - - deployment.yaml - - service.yaml -configMapGenerator: - - name: configmap-in-base - literals: - - foo=bar diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml deleted file mode 100644 index f6dd86909..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: nginx - labels: - app: nginx -spec: - ports: - - port: 80 - selector: - app: nginx diff --git a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml deleted file mode 100644 index 0b9aaf1b5..000000000 --- a/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: multiple patches no conflict -args: [] -filename: testdata/testcase-multiple-patches-noconflict/in/overlay/ -expectedStdout: testdata/testcase-multiple-patches-noconflict/expected.yaml -expectedDiff: testdata/testcase-multiple-patches-noconflict/expected.diff diff --git a/pkg/target/multiplepatch_test.go b/pkg/target/multiplepatch_test.go new file mode 100644 index 000000000..ac4e350c6 --- /dev/null +++ b/pkg/target/multiplepatch_test.go @@ -0,0 +1,293 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package target + +import ( + "strings" + "testing" +) + +func makeCommonFileForMultiplePatchTest(th *KustTestHarness) { + th.writeK("/app/base", ` +apiVersion: v1beta1 +kind: Kustomization +namePrefix: team-foo- +commonLabels: + app: mynginx + org: example.com + team: foo +commonAnnotations: + note: This is a test annotation +resources: + - deployment.yaml + - service.yaml +configMapGenerator: + - name: configmap-in-base + literals: + - foo=bar +`) + th.writeF("/app/base/deployment.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx + labels: + app: nginx +spec: + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + volumeMounts: + - name: nginx-persistent-storage + mountPath: /tmp/ps + volumes: + - name: nginx-persistent-storage + emptyDir: {} + - configMap: + name: configmap-in-base + name: configmap-in-base +`) + th.writeF("/app/base/service.yaml", ` +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + app: nginx +spec: + ports: + - port: 80 + selector: + app: nginx +`) + th.writeK("/app/overlay/staging", ` +apiVersion: v1beta1 +kind: Kustomization +namePrefix: staging- +commonLabels: + env: staging +patchesStrategicMerge: + - deployment-patch1.yaml + - deployment-patch2.yaml +bases: + - ../../base +configMapGenerator: + - name: configmap-in-overlay + literals: + - hello=world +`) +} + +func TestMultiplePatchesNoConflict(t *testing.T) { + th := NewKustTestHarness(t, "/app/overlay/staging") + makeCommonFileForMultiplePatchTest(th) + th.writeF("/app/overlay/staging/deployment-patch1.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + template: + spec: + containers: + - name: nginx + image: nginx:latest + env: + - name: ENVKEY + value: ENVVALUE + volumes: + - name: nginx-persistent-storage + emptyDir: null + gcePersistentDisk: + pdName: nginx-persistent-storage + - configMap: + name: configmap-in-overlay + name: configmap-in-overlay +`) + th.writeF("/app/overlay/staging/deployment-patch2.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + template: + spec: + containers: + - name: nginx + env: + - name: ANOTHERENV + value: FOO + - name: sidecar + image: sidecar + volumes: + - name: nginx-persistent-storage +`) + m, err := th.makeKustTarget().MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + th.assertActualEqualsExpected(m, ` +apiVersion: v1 +data: + foo: bar +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-g7k6gt2889 +--- +apiVersion: v1 +data: + hello: world +kind: ConfigMap +metadata: + labels: + env: staging + name: staging-configmap-in-overlay-k7cbc75tg8 +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: foo + name: staging-team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + env: staging + org: example.com + team: foo +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: foo + name: staging-team-foo-nginx +spec: + selector: + matchLabels: + app: mynginx + env: staging + org: example.com + team: foo + template: + metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: foo + spec: + containers: + - env: + - name: ANOTHERENV + value: FOO + - name: ENVKEY + value: ENVVALUE + image: nginx:latest + name: nginx + volumeMounts: + - mountPath: /tmp/ps + name: nginx-persistent-storage + - image: sidecar + name: sidecar + volumes: + - gcePersistentDisk: + pdName: nginx-persistent-storage + name: nginx-persistent-storage + - configMap: + name: staging-configmap-in-overlay-k7cbc75tg8 + name: configmap-in-overlay + - configMap: + name: staging-team-foo-configmap-in-base-g7k6gt2889 + name: configmap-in-base +`) +} + +func TestMultiplePatchesWithConflict(t *testing.T) { + th := NewKustTestHarness(t, "/app/overlay/staging") + makeCommonFileForMultiplePatchTest(th) + th.writeF("/app/overlay/staging/deployment-patch1.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + template: + spec: + containers: + - name: nginx + env: + - name: ENABLE_FEATURE_FOO + value: TRUE + volumes: + - name: nginx-persistent-storage + emptyDir: null + gcePersistentDisk: + pdName: nginx-persistent-storage + - configMap: + name: configmap-in-overlay + name: configmap-in-overlay +`) + th.writeF("/app/overlay/staging/deployment-patch2.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + template: + spec: + containers: + - name: nginx + env: + - name: ENABLE_FEATURE_FOO + value: FALSE +`) + _, err := th.makeKustTarget().MakeCustomizedResMap() + if err == nil { + t.Fatalf("expected conflict") + } + if !strings.Contains( + err.Error(), "conflict between ") { + t.Fatalf("Unexpected err: %v", err) + } +} diff --git a/pkg/target/utils_for_test.go b/pkg/target/utils_for_test.go index d3fedce95..8aebc4f8e 100644 --- a/pkg/target/utils_for_test.go +++ b/pkg/target/utils_for_test.go @@ -151,6 +151,9 @@ func (th *KustTestHarness) assertActualEqualsExpected( func (th *KustTestHarness) reportDiffAndFail(actual []byte, expected string) { sE, maxLen := convertToArray(expected) sA, _ := convertToArray(string(actual)) + fmt.Println("-- ACTUAL -----------------") + fmt.Println(string(actual)) + fmt.Println("---------------------------") format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4) limit := 0 if len(sE) < len(sA) {