From 243cbae41175f63671a9804c97a626dc3a9368f2 Mon Sep 17 00:00:00 2001 From: jregan Date: Sun, 16 Dec 2018 20:21:42 -0800 Subject: [PATCH] Convert file system based test to in-memory. --- pkg/commands/build/build_test.go | 4 +- .../testdata/testcase-simple/expected.diff | 154 ------------ .../testdata/testcase-simple/expected.yaml | 135 ---------- .../build/testdata/testcase-simple/test.yaml | 5 - .../exampleinstance/configmap/app-init.ini | 2 - .../exampleinstance/configmap/app.env | 2 - .../deployment/deployment.yaml | 43 ---- .../exampleinstance/kustomization.yaml | 28 --- .../instances/exampleinstance/secret/tls.cert | 12 - .../instances/exampleinstance/secret/tls.key | 9 - .../simple/package/Kube-descriptor.yaml | 14 -- .../simple/package/deployment/deployment.yaml | 21 -- .../simple/package/kustomization.yaml | 10 - .../simple/package/service/service.yaml | 11 - pkg/target/bigger_test.go | 230 ++++++++++++++++++ pkg/target/kusttarget_test.go | 36 ++- 16 files changed, 254 insertions(+), 462 deletions(-) delete mode 100644 pkg/commands/build/testdata/testcase-simple/expected.diff delete mode 100644 pkg/commands/build/testdata/testcase-simple/expected.yaml delete mode 100644 pkg/commands/build/testdata/testcase-simple/test.yaml delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/configmap/app-init.ini delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/configmap/app.env delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/deployment/deployment.yaml delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/secret/tls.cert delete mode 100644 pkg/examplelayout/simple/instances/exampleinstance/secret/tls.key delete mode 100644 pkg/examplelayout/simple/package/Kube-descriptor.yaml delete mode 100644 pkg/examplelayout/simple/package/deployment/deployment.yaml delete mode 100644 pkg/examplelayout/simple/package/kustomization.yaml delete mode 100644 pkg/examplelayout/simple/package/service/service.yaml create mode 100644 pkg/target/bigger_test.go diff --git a/pkg/commands/build/build_test.go b/pkg/commands/build/build_test.go index 98c2f99d3..ead4f6556 100644 --- a/pkg/commands/build/build_test.go +++ b/pkg/commands/build/build_test.go @@ -99,17 +99,15 @@ func TestBuild(t *testing.T) { return nil }) // sanity check that we found the right folder - if !kustfile.StringInSlice("simple", testcases) { + if !kustfile.StringInSlice("multiple-patches-noconflict", testcases) { t.Fatalf("Error locating testcases") } - for _, testcaseName := range testcases { t.Run(testcaseName, func(t *testing.T) { runBuildTestCase(t, testcaseName, updateKustomizeExpected, fSys) }) } - } func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fSys fs.FileSystem) { diff --git a/pkg/commands/build/testdata/testcase-simple/expected.diff b/pkg/commands/build/testdata/testcase-simple/expected.diff deleted file mode 100644 index fcd7ce640..000000000 --- a/pkg/commands/build/testdata/testcase-simple/expected.diff +++ /dev/null @@ -1,154 +0,0 @@ -diff -u -N /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml ---- /tmp/noop/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/extensions_v1beta1_Deployment_mungebot.yaml YYYY-MM-DD HH:MM:SS -@@ -3,28 +3,68 @@ - metadata: - annotations: - baseAnno: This is an base annotation -+ note: This is a test annotation - labels: - app: mungebot - foo: bar -- name: baseprefix-mungebot -+ org: kubernetes -+ repo: test-infra -+ name: test-infra-baseprefix-mungebot - spec: -- replicas: 1 -+ replicas: 2 - selector: - matchLabels: -+ app: mungebot - foo: bar -+ org: kubernetes -+ repo: test-infra - template: - metadata: - annotations: - baseAnno: This is an base annotation -+ note: This is a test annotation - labels: - app: mungebot - foo: bar -+ org: kubernetes -+ repo: test-infra - spec: - containers: - - env: -+ - name: FOO -+ valueFrom: -+ configMapKeyRef: -+ key: somekey -+ name: test-infra-app-env-bh449c299k -+ - name: BAR -+ valueFrom: -+ secretKeyRef: -+ key: somekey -+ name: test-infra-app-tls-6hkmhf2224 - - name: foo - value: bar -- image: nginx -+ image: nginx:1.8.0 - name: nginx - ports: - - containerPort: 80 -+ - envFrom: -+ - configMapRef: -+ name: someConfigMap -+ - configMapRef: -+ name: test-infra-app-env-bh449c299k -+ - secretRef: -+ name: test-infra-app-tls-6hkmhf2224 -+ image: busybox -+ name: busybox -+ volumeMounts: -+ - mountPath: /tmp/env -+ name: app-env -+ - mountPath: /tmp/tls -+ name: app-tls -+ volumes: -+ - configMap: -+ name: test-infra-app-env-bh449c299k -+ name: app-env -+ - name: app-tls -+ secret: -+ secretName: test-infra-app-tls-6hkmhf2224 -diff -u -N /tmp/noop/v1_ConfigMap_app-config.yaml /tmp/transformed/v1_ConfigMap_app-config.yaml ---- /tmp/noop/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_ConfigMap_app-config.yaml YYYY-MM-DD HH:MM:SS -@@ -0,0 +1,15 @@ -+apiVersion: v1 -+data: -+ app-init.ini: | -+ FOO=bar -+ BAR=baz -+kind: ConfigMap -+metadata: -+ annotations: -+ note: This is a test annotation -+ creationTimestamp: null -+ labels: -+ app: mungebot -+ org: kubernetes -+ repo: test-infra -+ name: test-infra-app-config-hf5424hg8g -diff -u -N /tmp/noop/v1_ConfigMap_app-env.yaml /tmp/transformed/v1_ConfigMap_app-env.yaml ---- /tmp/noop/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_ConfigMap_app-env.yaml YYYY-MM-DD HH:MM:SS -@@ -0,0 +1,14 @@ -+apiVersion: v1 -+data: -+ DB_PASSWORD: somepw -+ DB_USERNAME: admin -+kind: ConfigMap -+metadata: -+ annotations: -+ note: This is a test annotation -+ creationTimestamp: null -+ labels: -+ app: mungebot -+ org: kubernetes -+ repo: test-infra -+ name: test-infra-app-env-bh449c299k -diff -u -N /tmp/noop/v1_Secret_app-tls.yaml /tmp/transformed/v1_Secret_app-tls.yaml ---- /tmp/noop/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_Secret_app-tls.yaml YYYY-MM-DD HH:MM:SS -@@ -0,0 +1,15 @@ -+apiVersion: v1 -+data: -+ tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQkJRVUFNRVV4Q3pBSkJnTlYKQkFZVEFrRlZNUk13RVFZRFZRUUlEQXBUYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWAphV1JuYVhSeklGQjBlU0JNZEdRd0hoY05NVEl3T1RFeU1qRTFNakF5V2hjTk1UVXdPVEV5TWpFMU1qQXlXakJGCk1Rc3dDUVlEVlFRR0V3SkJWVEVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFaE1COEdBMVVFQ2d3WVNXNTAKWlhKdVpYUWdWMmxrWjJsMGN5QlFkSGtnVEhSa01Gd3dEUVlKS29aSWh2Y05BUUVCQlFBRFN3QXdTQUpCQU5MSgpoUEhoSVRxUWJQa2xHM2liQ1Z4d0dNUmZwL3Y0WHFoZmRRSGRjVmZIYXA2TlE1V29rLzR4SUErdWkzNS9NbU5hCnJ0TnVDK0JkWjF0TXVWQ1BGWmNDQXdFQUFhTlFNRTR3SFFZRFZSME9CQllFRkp2S3M4UmZKYVhUSDA4VytTR3YKelF5S24wSDhNQjhHQTFVZEl3UVlNQmFBRkp2S3M4UmZKYVhUSDA4VytTR3Z6UXlLbjBIOE1Bd0dBMVVkRXdRRgpNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUZCUUFEUVFCSmxmZkpIeWJqREd4Uk1xYVJtRGhYMCs2djAyVFVLWnNXCnI1UXVWYnBRaEg2dSswVWdjVzBqcDlRd3B4b1BUTFRXR1hFV0JCQnVyeEZ3aUNCaGtRK1YKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= -+ tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCT3dJQkFBSkJBTkxKaFBIaElUcVFiUGtsRzNpYkNWeHdHTVJmcC92NFhxaGZkUUhkY1ZmSGFwNk5RNVdvCmsvNHhJQSt1aTM1L01tTmFydE51QytCZFoxdE11VkNQRlpjQ0F3RUFBUUpBRUoyTit6c1IwWG44L1E2dHdhNEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo= -+kind: Secret -+metadata: -+ annotations: -+ note: This is a test annotation -+ creationTimestamp: null -+ labels: -+ app: mungebot -+ org: kubernetes -+ repo: test-infra -+ name: test-infra-app-tls-6hkmhf2224 -+type: kubernetes.io/tls -diff -u -N /tmp/noop/v1_Service_mungebot-service.yaml /tmp/transformed/v1_Service_mungebot-service.yaml ---- /tmp/noop/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS -+++ /tmp/transformed/v1_Service_mungebot-service.yaml YYYY-MM-DD HH:MM:SS -@@ -3,13 +3,18 @@ - metadata: - annotations: - baseAnno: This is an base annotation -+ note: This is a test annotation - labels: - app: mungebot - foo: bar -- name: baseprefix-mungebot-service -+ org: kubernetes -+ repo: test-infra -+ name: test-infra-baseprefix-mungebot-service - spec: - ports: - - port: 7002 - selector: - app: mungebot - foo: bar -+ org: kubernetes -+ repo: test-infra diff --git a/pkg/commands/build/testdata/testcase-simple/expected.yaml b/pkg/commands/build/testdata/testcase-simple/expected.yaml deleted file mode 100644 index f36471e2e..000000000 --- a/pkg/commands/build/testdata/testcase-simple/expected.yaml +++ /dev/null @@ -1,135 +0,0 @@ -apiVersion: v1 -data: - app-init.ini: | - FOO=bar - BAR=baz -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mungebot - org: kubernetes - repo: test-infra - name: test-infra-app-config-hf5424hg8g ---- -apiVersion: v1 -data: - DB_PASSWORD: somepw - DB_USERNAME: admin -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mungebot - org: kubernetes - repo: test-infra - name: test-infra-app-env-bh449c299k ---- -apiVersion: v1 -data: - tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQkJRVUFNRVV4Q3pBSkJnTlYKQkFZVEFrRlZNUk13RVFZRFZRUUlEQXBUYjIxbExWTjBZWFJsTVNFd0h3WURWUVFLREJoSmJuUmxjbTVsZENCWAphV1JuYVhSeklGQjBlU0JNZEdRd0hoY05NVEl3T1RFeU1qRTFNakF5V2hjTk1UVXdPVEV5TWpFMU1qQXlXakJGCk1Rc3dDUVlEVlFRR0V3SkJWVEVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFaE1COEdBMVVFQ2d3WVNXNTAKWlhKdVpYUWdWMmxrWjJsMGN5QlFkSGtnVEhSa01Gd3dEUVlKS29aSWh2Y05BUUVCQlFBRFN3QXdTQUpCQU5MSgpoUEhoSVRxUWJQa2xHM2liQ1Z4d0dNUmZwL3Y0WHFoZmRRSGRjVmZIYXA2TlE1V29rLzR4SUErdWkzNS9NbU5hCnJ0TnVDK0JkWjF0TXVWQ1BGWmNDQXdFQUFhTlFNRTR3SFFZRFZSME9CQllFRkp2S3M4UmZKYVhUSDA4VytTR3YKelF5S24wSDhNQjhHQTFVZEl3UVlNQmFBRkp2S3M4UmZKYVhUSDA4VytTR3Z6UXlLbjBIOE1Bd0dBMVVkRXdRRgpNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUZCUUFEUVFCSmxmZkpIeWJqREd4Uk1xYVJtRGhYMCs2djAyVFVLWnNXCnI1UXVWYnBRaEg2dSswVWdjVzBqcDlRd3B4b1BUTFRXR1hFV0JCQnVyeEZ3aUNCaGtRK1YKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= - tls.key: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlCT3dJQkFBSkJBTkxKaFBIaElUcVFiUGtsRzNpYkNWeHdHTVJmcC92NFhxaGZkUUhkY1ZmSGFwNk5RNVdvCmsvNHhJQSt1aTM1L01tTmFydE51QytCZFoxdE11VkNQRlpjQ0F3RUFBUUpBRUoyTit6c1IwWG44L1E2dHdhNEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo= -kind: Secret -metadata: - annotations: - note: This is a test annotation - labels: - app: mungebot - org: kubernetes - repo: test-infra - name: test-infra-app-tls-6hkmhf2224 -type: kubernetes.io/tls ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - baseAnno: This is an base annotation - note: This is a test annotation - labels: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra - name: test-infra-baseprefix-mungebot-service -spec: - ports: - - port: 7002 - selector: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra ---- -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - annotations: - baseAnno: This is an base annotation - note: This is a test annotation - labels: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra - name: test-infra-baseprefix-mungebot -spec: - replicas: 2 - selector: - matchLabels: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra - template: - metadata: - annotations: - baseAnno: This is an base annotation - note: This is a test annotation - labels: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra - spec: - containers: - - env: - - name: FOO - valueFrom: - configMapKeyRef: - key: somekey - name: test-infra-app-env-bh449c299k - - name: BAR - valueFrom: - secretKeyRef: - key: somekey - name: test-infra-app-tls-6hkmhf2224 - - name: foo - value: bar - image: nginx:1.8.0 - name: nginx - ports: - - containerPort: 80 - - envFrom: - - configMapRef: - name: someConfigMap - - configMapRef: - name: test-infra-app-env-bh449c299k - - secretRef: - name: test-infra-app-tls-6hkmhf2224 - image: busybox - name: busybox - volumeMounts: - - mountPath: /tmp/env - name: app-env - - mountPath: /tmp/tls - name: app-tls - volumes: - - configMap: - name: test-infra-app-env-bh449c299k - name: app-env - - name: app-tls - secret: - secretName: test-infra-app-tls-6hkmhf2224 diff --git a/pkg/commands/build/testdata/testcase-simple/test.yaml b/pkg/commands/build/testdata/testcase-simple/test.yaml deleted file mode 100644 index 82bc2939e..000000000 --- a/pkg/commands/build/testdata/testcase-simple/test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -description: simple -args: [] -filename: ../../examplelayout/simple/instances/exampleinstance/ -expectedStdout: testdata/testcase-simple/expected.yaml -expectedDiff: testdata/testcase-simple/expected.diff diff --git a/pkg/examplelayout/simple/instances/exampleinstance/configmap/app-init.ini b/pkg/examplelayout/simple/instances/exampleinstance/configmap/app-init.ini deleted file mode 100644 index 8ebb8fcb3..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/configmap/app-init.ini +++ /dev/null @@ -1,2 +0,0 @@ -FOO=bar -BAR=baz diff --git a/pkg/examplelayout/simple/instances/exampleinstance/configmap/app.env b/pkg/examplelayout/simple/instances/exampleinstance/configmap/app.env deleted file mode 100644 index c4032090a..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/configmap/app.env +++ /dev/null @@ -1,2 +0,0 @@ -DB_USERNAME=admin -DB_PASSWORD=somepw diff --git a/pkg/examplelayout/simple/instances/exampleinstance/deployment/deployment.yaml b/pkg/examplelayout/simple/instances/exampleinstance/deployment/deployment.yaml deleted file mode 100644 index c6a060d55..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/deployment/deployment.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: mungebot -spec: - replicas: 2 - template: - spec: - containers: - - name: nginx - image: nginx:1.7.9 - env: - - name: FOO - valueFrom: - configMapKeyRef: - name: app-env - key: somekey - - name: BAR - valueFrom: - secretKeyRef: - name: app-tls - key: somekey - - name: busybox - image: busybox - envFrom: - - configMapRef: - name: someConfigMap - - configMapRef: - name: app-env - - secretRef: - name: app-tls - volumeMounts: - - mountPath: /tmp/env - name: app-env - - mountPath: /tmp/tls - name: app-tls - volumes: - - configMap: - name: app-env - name: app-env - - secret: - secretName: app-tls - name: app-tls diff --git a/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml b/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml deleted file mode 100644 index f16073490..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/kustomization.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: v1 -kind: Kustomization -namePrefix: test-infra- -commonLabels: - app: mungebot - org: kubernetes - repo: test-infra -commonAnnotations: - note: This is a test annotation -bases: -- ../../package/ -patchesStrategicMerge: -- deployment/deployment.yaml -configMapGenerator: -- name: app-env - env: configmap/app.env -- name: app-config - files: - - configmap/app-init.ini -secretGenerator: -- name: app-tls - commands: - tls.crt: "cat secret/tls.cert" - tls.key: "cat secret/tls.key" - type: "kubernetes.io/tls" -imageTags: -- name: nginx - newTag: 1.8.0 diff --git a/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.cert b/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.cert deleted file mode 100644 index 039a9cadf..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.cert +++ /dev/null @@ -1,12 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIB0zCCAX2gAwIBAgIJAI/M7BYjwB+uMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTIwOTEyMjE1MjAyWhcNMTUwOTEyMjE1MjAyWjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLJ -hPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wok/4xIA+ui35/MmNa -rtNuC+BdZ1tMuVCPFZcCAwEAAaNQME4wHQYDVR0OBBYEFJvKs8RfJaXTH08W+SGv -zQyKn0H8MB8GA1UdIwQYMBaAFJvKs8RfJaXTH08W+SGvzQyKn0H8MAwGA1UdEwQF -MAMBAf8wDQYJKoZIhvcNAQEFBQADQQBJlffJHybjDGxRMqaRmDhX0+6v02TUKZsW -r5QuVbpQhH6u+0UgcW0jp9QwpxoPTLTWGXEWBBBurxFwiCBhkQ+V ------END CERTIFICATE----- diff --git a/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.key b/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.key deleted file mode 100644 index a748bb8ae..000000000 --- a/pkg/examplelayout/simple/instances/exampleinstance/secret/tls.key +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIBOwIBAAJBANLJhPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wo -k/4xIA+ui35/MmNartNuC+BdZ1tMuVCPFZcCAwEAAQJAEJ2N+zsR0Xn8/Q6twa4G -6OB1M1WO+k+ztnX/1SvNeWu8D6GImtupLTYgjZcHufykj09jiHmjHx8u8ZZB/o1N -MQIhAPW+eyZo7ay3lMz1V01WVjNKK9QSn1MJlb06h/LuYv9FAiEA25WPedKgVyCW -SmUwbPw8fnTcpqDWE3yTO3vKcebqMSsCIBF3UmVue8YU3jybC3NxuXq3wNm34R8T -xVLHwDXh/6NJAiEAl2oHGGLz64BuAfjKrqwz7qMYr9HCLIe/YsoWq/olzScCIQDi -D2lWusoe2/nEqfDVVWGWlyJ7yOmqaVm/iNUN9B2N2g== ------END RSA PRIVATE KEY----- diff --git a/pkg/examplelayout/simple/package/Kube-descriptor.yaml b/pkg/examplelayout/simple/package/Kube-descriptor.yaml deleted file mode 100644 index a26036374..000000000 --- a/pkg/examplelayout/simple/package/Kube-descriptor.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# This example is from https://docs.google.com/document/d/1cLPGweVEYrVqQvBLJg6sxV-TrE5Rm2MNOBA_cxZP2WU/edit#heading=h.dr88tktf0e99 - -# Inspired by https://github.com/kubernetes/helm/blob/master/docs/charts.md -# But Kubernetes API style -apiVersion: manifest.k8s.io/v1alpha1 -kind: Descriptor -metadata: - name: mungebot -description: Mungegithub package -# These are search keywords -keywords: [github, bot, kubernetes] -home: https://github.com/bgrant0607/mungebot-pkg/blob/master/README.md -sources: https://github.com/bgrant0607/mungebot-pkg -icon: https://github.com/bgrant0607/mungebot-pkg/blob/master/icon.png diff --git a/pkg/examplelayout/simple/package/deployment/deployment.yaml b/pkg/examplelayout/simple/package/deployment/deployment.yaml deleted file mode 100644 index 9582b0056..000000000 --- a/pkg/examplelayout/simple/package/deployment/deployment.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: mungebot - labels: - app: mungebot -spec: - replicas: 1 - template: - metadata: - labels: - app: mungebot - spec: - containers: - - name: nginx - image: nginx - env: - - name: foo - value: bar - ports: - - containerPort: 80 diff --git a/pkg/examplelayout/simple/package/kustomization.yaml b/pkg/examplelayout/simple/package/kustomization.yaml deleted file mode 100644 index 82bc52e23..000000000 --- a/pkg/examplelayout/simple/package/kustomization.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: Kustomization -namePrefix: baseprefix- -commonLabels: - foo: bar -commonAnnotations: - baseAnno: This is an base annotation -resources: -- deployment/deployment.yaml -- service/service.yaml diff --git a/pkg/examplelayout/simple/package/service/service.yaml b/pkg/examplelayout/simple/package/service/service.yaml deleted file mode 100644 index e8fb0c806..000000000 --- a/pkg/examplelayout/simple/package/service/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: mungebot-service - labels: - app: mungebot -spec: - ports: - - port: 7002 - selector: - app: mungebot diff --git a/pkg/target/bigger_test.go b/pkg/target/bigger_test.go new file mode 100644 index 000000000..728b21c7d --- /dev/null +++ b/pkg/target/bigger_test.go @@ -0,0 +1,230 @@ +/* +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" + + "sigs.k8s.io/kustomize/pkg/internal/loadertest" +) + +// TODO(monopole): Add a feature test example covering secret generation. + +// WARNING: These tests use a fake file system, and any attempt to use a +// feature that spawns shells will fail, because said shells expect a working +// directory corresponding to a real directory on disk - see +// these lines in secretfactory.go: +// cmd := exec.CommandContext(ctx, commands[0], commands[1:]...) +// cmd.Dir = f.wd +// Worse, the fake directory might match a real directory on the your system, +// making the failure less obvious (and maybe hurting something if your secret +// generation technique writes data to disk). So no use of secret generation +// in these particular tests. +// To eventually fix this, we could write the data to a real filesystem, and +// clean up after, or use some other trick compatible with exec. + +func writeBase(t *testing.T, ldr loadertest.FakeLoader) { + writeK(t, ldr, "/app/base", ` +namePrefix: baseprefix- +commonLabels: + foo: bar +commonAnnotations: + baseAnno: This is a base annotation +resources: +- deployment/deployment.yaml +- service/service.yaml +`) + writeF(t, ldr, "/app/base/service/service.yaml", ` +apiVersion: v1 +kind: Service +metadata: + name: mungebot-service + labels: + app: mungebot +spec: + ports: + - port: 7002 + selector: + app: mungebot +`) + writeF(t, ldr, "/app/base/deployment/deployment.yaml", ` +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: mungebot + labels: + app: mungebot +spec: + replicas: 1 + template: + metadata: + labels: + app: mungebot + spec: + containers: + - name: nginx + image: nginx + env: + - name: foo + value: bar + ports: + - containerPort: 80 +`) + +} + +func TestBigBase(t *testing.T) { + ldr := loadertest.NewFakeLoader("/app/base") + writeBase(t, ldr) + m, err := makeKustTarget(t, ldr).MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + if m == nil { + t.Fatalf("Empty map.") + } + s, err := m.EncodeAsYaml() + if err != nil { + t.Fatalf("Err: %v", err) + } + expected := `apiVersion: v1 +kind: Service +metadata: + annotations: + baseAnno: This is a base annotation + labels: + app: mungebot + foo: bar + name: baseprefix-mungebot-service +spec: + ports: + - port: 7002 + selector: + app: mungebot + foo: bar +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + annotations: + baseAnno: This is a base annotation + labels: + app: mungebot + foo: bar + name: baseprefix-mungebot +spec: + replicas: 1 + selector: + matchLabels: + foo: bar + template: + metadata: + annotations: + baseAnno: This is a base annotation + labels: + app: mungebot + foo: bar + spec: + containers: + - env: + - name: foo + value: bar + image: nginx + name: nginx + ports: + - containerPort: 80 +` + if string(s) != expected { + t.Fatalf("Actual results:\n%s\nnot equal to expected:\n%s\n", + s, expected) + } +} + +func TestBigOverlay(t *testing.T) { + ldr := loadertest.NewFakeLoader("/app/overlay") + writeBase(t, ldr) + writeK(t, ldr, "/app/overlay", ` +namePrefix: test-infra- +commonLabels: + app: mungebot + org: kubernetes + repo: test-infra +commonAnnotations: + note: This is a test annotation +bases: +- ../base +patchesStrategicMerge: +- deployment/deployment.yaml +configMapGenerator: +- name: app-env + env: configmap/app.env +- name: app-config + files: + - configmap/app-init.ini +imageTags: +- name: nginx + newTag: 1.8.0`) + + writeF(t, ldr, "/app/overlay/configmap/app.env", ` +DB_USERNAME=admin +DB_PASSWORD=somepw +`) + writeF(t, ldr, "/app/overlay/configmap/app-init.ini", ` +FOO=bar +BAR=baz +`) + writeF(t, ldr, "/app/overlay/deployment/deployment.yaml", ` +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: mungebot +spec: + replicas: 2 + template: + spec: + containers: + - name: nginx + image: nginx:1.7.9 + env: + - name: FOO + valueFrom: + configMapKeyRef: + name: app-env + key: somekey + - name: busybox + image: busybox + envFrom: + - configMapRef: + name: someConfigMap + - configMapRef: + name: app-env + volumeMounts: + - mountPath: /tmp/env + name: app-env + volumes: + - configMap: + name: app-env + name: app-env +`) + m, err := makeKustTarget(t, ldr).MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + if m == nil { + t.Fatalf("Empty map.") + } +} diff --git a/pkg/target/kusttarget_test.go b/pkg/target/kusttarget_test.go index 3442ec15f..b8deb6075 100644 --- a/pkg/target/kusttarget_test.go +++ b/pkg/target/kusttarget_test.go @@ -98,6 +98,13 @@ var rf = resmap.NewFactory(resource.NewFactory( kunstruct.NewKunstructuredFactoryImpl())) func makeKustTarget(t *testing.T, l ifc.Loader) *KustTarget { + // Warning: the following filesystem - a fake - must be rooted at /. + // This fs root is used as the working directory for the shell spawned by + // the secretgenerator, and has nothing to do with the filesystem used + // to load relative paths from the fake filesystem. + // This trick only works for secret generator commands that don't actually + // try to read the file system, because these tests don't write to the + // real "/" directory. See use of exec package in the secretfactory. fakeFs := fs.MakeFakeFS() fakeFs.Mkdir("/") kt, err := NewKustTarget( @@ -245,7 +252,7 @@ func TestResourceNotFound(t *testing.T) { if err == nil { t.Fatalf("Didn't get the expected error for an unknown resource") } - if !strings.Contains(err.Error(), `cannot read file "/testpath/deployment.yaml"`) { + if !strings.Contains(err.Error(), `cannot read file`) { t.Fatalf("unexpected error: %q", err) } } @@ -304,31 +311,34 @@ func TestDisableNameSuffixHash(t *testing.T) { } } -func write(t *testing.T, ldr loadertest.FakeLoader, dir string, content string) { - err := ldr.AddFile( - filepath.Join(dir, constants.KustomizationFileName), - []byte(` +func writeF(t *testing.T, ldr loadertest.FakeLoader, dir string, content string) { + err := ldr.AddFile(dir, []byte(content)) + if err != nil { + t.Fatalf("failed write to %s; %v", dir, err) + } +} + +func writeK( + t *testing.T, ldr loadertest.FakeLoader, dir string, content string) { + writeF(t, ldr, filepath.Join(dir, constants.KustomizationFileName), ` apiVersion: v1 kind: Kustomization -`+content)) - if err != nil { - t.Fatalf("Failed to setup fake loader.") - } +`+content) } func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) { ldr := loadertest.NewFakeLoader( "/app/overlays/aws-sandbox2.us-east-1") - write(t, ldr, "/app/base", "") - write(t, ldr, "/app/overlays/aws", ` + writeK(t, ldr, "/app/base", "") + writeK(t, ldr, "/app/overlays/aws", ` bases: - ../../base `) - write(t, ldr, "/app/overlays/aws-nonprod", ` + writeK(t, ldr, "/app/overlays/aws-nonprod", ` bases: - ../aws `) - write(t, ldr, "/app/overlays/aws-sandbox2.us-east-1", ` + writeK(t, ldr, "/app/overlays/aws-sandbox2.us-east-1", ` bases: - ../aws-nonprod `)