diff --git a/pkg/commands/build/testdata/testcase-base-only/expected.diff b/pkg/commands/build/testdata/testcase-base-only/expected.diff deleted file mode 100644 index 5dba387e1..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/expected.diff +++ /dev/null @@ -1,85 +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 -@@ -1,14 +1,27 @@ - apiVersion: apps/v1beta2 - kind: Deployment - metadata: -+ annotations: -+ note: This is a test annotation - labels: -- app: nginx -- name: nginx -+ app: mynginx -+ org: example.com -+ team: foo -+ name: team-foo-nginx - spec: -+ selector: -+ matchLabels: -+ app: mynginx -+ org: example.com -+ team: foo - template: - metadata: -+ annotations: -+ note: This is a test annotation - labels: -- app: nginx -+ app: mynginx -+ org: example.com -+ team: foo - spec: - containers: - - image: nginx -diff -u -N /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml ---- /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS -@@ -1,13 +1,21 @@ - apiVersion: networking.k8s.io/v1 - kind: NetworkPolicy - metadata: -- name: nginx -+ annotations: -+ note: This is a test annotation -+ labels: -+ app: mynginx -+ org: example.com -+ team: foo -+ name: team-foo-nginx - spec: - ingress: - - from: - - podSelector: - matchLabels: -- app: nginx -+ app: mynginx -+ org: example.com -+ team: foo - podSelector: - matchExpressions: - - key: app -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 -@@ -1,11 +1,17 @@ - apiVersion: v1 - kind: Service - metadata: -+ annotations: -+ note: This is a test annotation - labels: -- app: nginx -- name: nginx -+ app: mynginx -+ org: example.com -+ team: foo -+ name: team-foo-nginx - spec: - ports: - - port: 80 - selector: -- app: nginx -+ app: mynginx -+ org: example.com -+ team: foo diff --git a/pkg/commands/build/testdata/testcase-base-only/expected.yaml b/pkg/commands/build/testdata/testcase-base-only/expected.yaml deleted file mode 100644 index 966cec3a2..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/expected.yaml +++ /dev/null @@ -1,71 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - org: example.com - team: foo ---- -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-nginx -spec: - selector: - matchLabels: - app: mynginx - org: example.com - team: foo - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - spec: - containers: - - image: nginx - name: nginx ---- -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-nginx -spec: - ingress: - - from: - - podSelector: - matchLabels: - app: mynginx - org: example.com - team: foo - podSelector: - matchExpressions: - - key: app - operator: In - values: - - test diff --git a/pkg/commands/build/testdata/testcase-base-only/in/kustomization.yaml b/pkg/commands/build/testdata/testcase-base-only/in/kustomization.yaml deleted file mode 100644 index 75bcee92f..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/in/kustomization.yaml +++ /dev/null @@ -1,13 +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: - - resources/deployment.yaml - - resources/networkpolicy.yaml - - resources/service.yaml diff --git a/pkg/commands/build/testdata/testcase-base-only/in/resources/deployment.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/deployment.yaml deleted file mode 100644 index 722bf87ce..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/in/resources/deployment.yaml +++ /dev/null @@ -1,15 +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 diff --git a/pkg/commands/build/testdata/testcase-base-only/in/resources/networkpolicy.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/networkpolicy.yaml deleted file mode 100644 index 213801ce1..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/in/resources/networkpolicy.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - name: nginx -spec: - podSelector: - matchExpressions: - - {key: app, operator: In, values: [test]} - ingress: - - from: - - podSelector: - matchLabels: - app: nginx diff --git a/pkg/commands/build/testdata/testcase-base-only/in/resources/service.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/service.yaml deleted file mode 100644 index f6dd86909..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/in/resources/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-base-only/test.yaml b/pkg/commands/build/testdata/testcase-base-only/test.yaml deleted file mode 100644 index 61d6d0a07..000000000 --- a/pkg/commands/build/testdata/testcase-base-only/test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: base only -args: [] -filename: testdata/testcase-base-only/in -expectedStdout: testdata/testcase-base-only/expected.yaml -expectedDiff: testdata/testcase-base-only/expected.diff diff --git a/pkg/commands/build/testdata/testcase-single-overlay/expected.diff b/pkg/commands/build/testdata/testcase-single-overlay/expected.diff deleted file mode 100644 index d27e1da5f..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/expected.diff +++ /dev/null @@ -1,128 +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,23 +5,26 @@ - note: This is a test annotation - labels: - app: mynginx -+ env: staging - org: example.com -- team: foo -- name: team-foo-nginx -+ team: override-foo -+ name: staging-team-foo-nginx - spec: - selector: - matchLabels: - app: mynginx -+ env: staging - org: example.com -- team: foo -+ team: override-foo - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx -+ env: staging - org: example.com -- team: foo -+ team: override-foo - spec: - containers: - - image: nginx -@@ -30,8 +33,12 @@ - - mountPath: /tmp/ps - name: nginx-persistent-storage - 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-gh9d7t85gb - 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 -@@ -1,6 +1,6 @@ - apiVersion: v1 - data: -- foo: bar -+ foo: override-bar - kind: ConfigMap - metadata: - annotations: -@@ -8,6 +8,7 @@ - creationTimestamp: null - labels: - app: mynginx -+ env: staging - org: example.com -- team: foo -- name: team-foo-configmap-in-base-bbdmdh7m8t -+ team: override-foo -+ name: staging-team-foo-configmap-in-base-gh9d7t85gb -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,10 @@ -+apiVersion: v1 -+data: -+ hello: world -+kind: ConfigMap -+metadata: -+ creationTimestamp: null -+ labels: -+ env: staging -+ team: override-foo -+ name: staging-configmap-in-overlay-k7cbc75tg8 -diff -u -N /tmp/noop/v1_Secret_secret-in-base.yaml /tmp/transformed/v1_Secret_secret-in-base.yaml ---- /tmp/noop/v1_Secret_secret-in-base.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_Secret_secret-in-base.yaml YYYY-MM-DD HH:MM:SS -@@ -1,6 +1,7 @@ - apiVersion: v1 - data: - password: c29tZXB3 -+ proxy: aGFwcm94eQ== - username: YWRtaW4= - kind: Secret - metadata: -@@ -9,7 +10,8 @@ - creationTimestamp: null - labels: - app: mynginx -+ env: staging - org: example.com -- team: foo -- name: team-foo-secret-in-base-tkm7hhtf8d -+ team: override-foo -+ name: staging-team-foo-secret-in-base-c8db7gk2m2 - type: Opaque -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 -+ team: override-foo -+ name: staging-team-foo-nginx - spec: - ports: - - port: 80 - selector: - app: mynginx -+ env: staging - org: example.com -- team: foo -+ team: override-foo diff --git a/pkg/commands/build/testdata/testcase-single-overlay/expected.yaml b/pkg/commands/build/testdata/testcase-single-overlay/expected.yaml deleted file mode 100644 index 9a6fcac31..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/expected.yaml +++ /dev/null @@ -1,105 +0,0 @@ -apiVersion: v1 -data: - foo: override-bar -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-configmap-in-base-gh9d7t85gb ---- -apiVersion: v1 -data: - hello: world -kind: ConfigMap -metadata: - labels: - env: staging - team: override-foo - name: staging-configmap-in-overlay-k7cbc75tg8 ---- -apiVersion: v1 -data: - password: c29tZXB3 - proxy: aGFwcm94eQ== - username: YWRtaW4= -kind: Secret -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-secret-in-base-c8db7gk2m2 -type: Opaque ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - env: staging - org: example.com - team: override-foo ---- -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-nginx -spec: - selector: - matchLabels: - app: mynginx - env: staging - org: example.com - team: override-foo - template: - metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - spec: - containers: - - image: nginx - name: nginx - volumeMounts: - - mountPath: /tmp/ps - name: nginx-persistent-storage - 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-gh9d7t85gb - name: configmap-in-base diff --git a/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/deployment.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/deployment.yaml deleted file mode 100644 index ae8bc1280..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/deployment.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - template: - spec: - 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-single-overlay/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/kustomization.yaml deleted file mode 100644 index 307752281..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/kustomization.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: v1beta1 -kind: Kustomization -namePrefix: staging- -commonLabels: - env: staging - team: override-foo -patchesStrategicMerge: - - deployment.yaml -bases: - - ../package/ -configMapGenerator: - - name: configmap-in-overlay - literals: - - hello=world - - name: configmap-in-base - behavior: replace - literals: - - foo=override-bar -secretGenerator: -- name: secret-in-base - behavior: merge - commands: - proxy: "printf haproxy" diff --git a/pkg/commands/build/testdata/testcase-single-overlay/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/deployment.yaml deleted file mode 100644 index 9f7d3cbb6..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/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-single-overlay/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/kustomization.yaml deleted file mode 100644 index 5ea5cab5f..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/in/package/kustomization.yaml +++ /dev/null @@ -1,21 +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 -secretGenerator: -- name: secret-in-base - commands: - username: "printf admin" - password: "printf somepw" diff --git a/pkg/commands/build/testdata/testcase-single-overlay/in/package/service.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/service.yaml deleted file mode 100644 index f6dd86909..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/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-single-overlay/test.yaml b/pkg/commands/build/testdata/testcase-single-overlay/test.yaml deleted file mode 100644 index 1af80f52c..000000000 --- a/pkg/commands/build/testdata/testcase-single-overlay/test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: single overlay -args: [] -filename: testdata/testcase-single-overlay/in/overlay/ -expectedStdout: testdata/testcase-single-overlay/expected.yaml -expectedDiff: testdata/testcase-single-overlay/expected.diff diff --git a/pkg/target/generatormergeandreplace_test.go b/pkg/target/generatormergeandreplace_test.go new file mode 100644 index 000000000..365b41006 --- /dev/null +++ b/pkg/target/generatormergeandreplace_test.go @@ -0,0 +1,479 @@ +/* +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 ( + "testing" +) + +func TestSimpleBase(t *testing.T) { + th := NewKustTestHarness(t, "/app/base") + 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 + - networkpolicy.yaml + - service.yaml +`) + th.writeF("/app/base/service.yaml", ` +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + app: nginx +spec: + ports: + - port: 80 + selector: + app: nginx +`) + th.writeF("/app/base/networkpolicy.yaml", ` +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: nginx +spec: + podSelector: + matchExpressions: + - {key: app, operator: In, values: [test]} + ingress: + - from: + - podSelector: + matchLabels: + app: nginx +`) + 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 +`) + m, err := th.makeKustTarget().MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + th.assertActualEqualsExpected(m, ` +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + org: example.com + team: foo +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + selector: + matchLabels: + app: mynginx + org: example.com + team: foo + template: + metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + spec: + containers: + - image: nginx + name: nginx +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + ingress: + - from: + - podSelector: + matchLabels: + app: mynginx + org: example.com + team: foo + podSelector: + matchExpressions: + - key: app + operator: In + values: + - test +`) +} + +func makeBaseWithGenerators(th *KustTestHarness) { + th.writeK("/app", ` +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 +secretGenerator: +- name: secret-in-base + commands: + username: "printf admin" + password: "printf somepw" +`) + th.writeF("/app/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/service.yaml", ` +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + app: nginx +spec: + ports: + - port: 80 + selector: + app: nginx +`) +} + +func TestBaseWithGeneratorsAlone(t *testing.T) { + th := NewKustTestHarness(t, "/app") + makeBaseWithGenerators(th) + 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 + org: example.com + team: foo + name: team-foo-configmap-in-base-bbdmdh7m8t +--- +apiVersion: v1 +data: + password: c29tZXB3 + username: YWRtaW4= +kind: Secret +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-secret-in-base-tkm7hhtf8d +type: Opaque +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + org: example.com + team: foo +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + selector: + matchLabels: + app: mynginx + org: example.com + team: foo + template: + metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + spec: + containers: + - image: nginx + name: nginx + volumeMounts: + - mountPath: /tmp/ps + name: nginx-persistent-storage + volumes: + - emptyDir: {} + name: nginx-persistent-storage + - configMap: + name: team-foo-configmap-in-base-bbdmdh7m8t + name: configmap-in-base +`) +} + +func TestMergeAndReplaceGenerators(t *testing.T) { + th := NewKustTestHarness(t, "/overlay") + makeBaseWithGenerators(th) + th.writeF("/overlay/deployment.yaml", ` +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + template: + spec: + volumes: + - name: nginx-persistent-storage + emptyDir: null + gcePersistentDisk: + pdName: nginx-persistent-storage + - configMap: + name: configmap-in-overlay + name: configmap-in-overlay +`) + th.writeK("/overlay", ` +apiVersion: v1beta1 +kind: Kustomization +namePrefix: staging- +commonLabels: + env: staging + team: override-foo +patchesStrategicMerge: + - deployment.yaml +bases: + - ../app +configMapGenerator: + - name: configmap-in-overlay + literals: + - hello=world + - name: configmap-in-base + behavior: replace + literals: + - foo=override-bar +secretGenerator: +- name: secret-in-base + behavior: merge + commands: + proxy: "printf haproxy" +`) + m, err := th.makeKustTarget().MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + th.assertActualEqualsExpected(m, ` +apiVersion: v1 +data: + foo: override-bar +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-configmap-in-base-gh9d7t85gb +--- +apiVersion: v1 +data: + hello: world +kind: ConfigMap +metadata: + labels: + env: staging + team: override-foo + name: staging-configmap-in-overlay-k7cbc75tg8 +--- +apiVersion: v1 +data: + password: c29tZXB3 + proxy: aGFwcm94eQ== + username: YWRtaW4= +kind: Secret +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-secret-in-base-c8db7gk2m2 +type: Opaque +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + env: staging + org: example.com + team: override-foo +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-nginx +spec: + selector: + matchLabels: + app: mynginx + env: staging + org: example.com + team: override-foo + template: + metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + spec: + containers: + - image: nginx + name: nginx + volumeMounts: + - mountPath: /tmp/ps + name: nginx-persistent-storage + 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-gh9d7t85gb + name: configmap-in-base +`) +}