From c68ae28e40844748c4ff9418866c9e91c3f884c2 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Wed, 24 Jun 2020 16:42:50 +0200 Subject: [PATCH] fix: test errors (TBS) --- docs/example-projects/using-garden-in-ci.md | 2 +- examples/build-dependencies/garden.yml | 2 +- examples/deployment-strategies/garden.yml | 2 +- examples/disabled-configs/garden.yml | 2 +- examples/hadolint/garden.yml | 2 +- .../hot-reload-post-sync-command/garden.yml | 2 +- examples/hot-reload/garden.yml | 2 +- examples/kaniko/garden.yml | 2 +- examples/kubernetes-secrets/garden.yml | 2 +- examples/openfaas/garden.yml | 2 +- examples/project-variables/garden.yml | 2 +- examples/remote-sources/garden.yml | 2 +- examples/tasks/garden.yml | 2 +- examples/vote-helm/garden.yml | 2 +- examples/vote/garden.yml | 2 +- .../src/plugins/kubernetes/kubectl.ts | 18 +++++++++--------- garden-service/src/plugins/kubernetes/run.ts | 2 +- .../plugins/kubernetes/container/container.ts | 4 ++-- .../plugins/kubernetes/container/deployment.ts | 13 +++++++------ .../test/integ/src/plugins/kubernetes/util.ts | 2 +- 20 files changed, 35 insertions(+), 34 deletions(-) diff --git a/docs/example-projects/using-garden-in-ci.md b/docs/example-projects/using-garden-in-ci.md index 4e5d360091..aaa199c6b6 100644 --- a/docs/example-projects/using-garden-in-ci.md +++ b/docs/example-projects/using-garden-in-ci.md @@ -44,7 +44,7 @@ name: ci-demo-project environments: ... - name: preview - defaultNamespace: ${project.name}-${local.env.CIRCLE_BRANCH || local.username} + defaultNamespace: preview-${local.env.CIRCLE_BRANCH || local.username} providers: - name: kubernetes environments: [preview] diff --git a/examples/build-dependencies/garden.yml b/examples/build-dependencies/garden.yml index 61c9652925..1f823e419b 100644 --- a/examples/build-dependencies/garden.yml +++ b/examples/build-dependencies/garden.yml @@ -4,7 +4,7 @@ name: build-dependencies environments: - name: local - name: remote - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/deployment-strategies/garden.yml b/examples/deployment-strategies/garden.yml index be12b85818..39d959d9d8 100644 --- a/examples/deployment-strategies/garden.yml +++ b/examples/deployment-strategies/garden.yml @@ -5,7 +5,7 @@ environments: - name: local-default - name: local-blue-green - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: # Default deployment strategy - name: local-kubernetes diff --git a/examples/disabled-configs/garden.yml b/examples/disabled-configs/garden.yml index b3e5d2cad7..6b57289b05 100644 --- a/examples/disabled-configs/garden.yml +++ b/examples/disabled-configs/garden.yml @@ -7,9 +7,9 @@ environments: providers: - name: local-kubernetes environments: [local] - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} - name: kubernetes environments: [remote] + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} # Replace these values as appropriate context: gke_garden-dev-200012_europe-west1-b_garden-dev-1 defaultHostname: ${local.username}-disabled-configs.dev-1.sys.garden diff --git a/examples/hadolint/garden.yml b/examples/hadolint/garden.yml index f7679746a6..cea414aa23 100644 --- a/examples/hadolint/garden.yml +++ b/examples/hadolint/garden.yml @@ -3,7 +3,7 @@ name: demo-project environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: hadolint - name: local-kubernetes diff --git a/examples/hot-reload-post-sync-command/garden.yml b/examples/hot-reload-post-sync-command/garden.yml index e2eadba9a4..5891509863 100644 --- a/examples/hot-reload-post-sync-command/garden.yml +++ b/examples/hot-reload-post-sync-command/garden.yml @@ -3,7 +3,7 @@ name: hot-reload-post-sync-command environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/hot-reload/garden.yml b/examples/hot-reload/garden.yml index 1bd84c1696..2480899bae 100644 --- a/examples/hot-reload/garden.yml +++ b/examples/hot-reload/garden.yml @@ -3,7 +3,7 @@ name: hot-reload environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/kaniko/garden.yml b/examples/kaniko/garden.yml index cb19d29442..5e8e289075 100644 --- a/examples/kaniko/garden.yml +++ b/examples/kaniko/garden.yml @@ -4,7 +4,7 @@ name: kaniko environments: - name: local - name: remote - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/kubernetes-secrets/garden.yml b/examples/kubernetes-secrets/garden.yml index 2fe9209e5b..fc9ea6d9a0 100644 --- a/examples/kubernetes-secrets/garden.yml +++ b/examples/kubernetes-secrets/garden.yml @@ -3,7 +3,7 @@ name: kubernetes-secrets environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/openfaas/garden.yml b/examples/openfaas/garden.yml index bb434ff697..f2987ebc7c 100644 --- a/examples/openfaas/garden.yml +++ b/examples/openfaas/garden.yml @@ -3,7 +3,7 @@ name: openfaas environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/project-variables/garden.yml b/examples/project-variables/garden.yml index 62817b4d68..33695448ab 100644 --- a/examples/project-variables/garden.yml +++ b/examples/project-variables/garden.yml @@ -9,7 +9,7 @@ environments: # We only want one replica of each service when developing locally service-replicas: 1 - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/remote-sources/garden.yml b/examples/remote-sources/garden.yml index 79ec531ce0..7f00890cfd 100644 --- a/examples/remote-sources/garden.yml +++ b/examples/remote-sources/garden.yml @@ -8,7 +8,7 @@ sources: environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/tasks/garden.yml b/examples/tasks/garden.yml index 3a258f8882..cc00ef6fc9 100644 --- a/examples/tasks/garden.yml +++ b/examples/tasks/garden.yml @@ -3,7 +3,7 @@ name: tasks environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/vote-helm/garden.yml b/examples/vote-helm/garden.yml index 336b7fd40e..0733d2354f 100644 --- a/examples/vote-helm/garden.yml +++ b/examples/vote-helm/garden.yml @@ -3,7 +3,7 @@ name: vote-helm environments: - name: local - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/examples/vote/garden.yml b/examples/vote/garden.yml index 68d7fba557..d9320828b5 100644 --- a/examples/vote/garden.yml +++ b/examples/vote/garden.yml @@ -4,7 +4,7 @@ environments: - name: local - name: remote - name: testing - defaultNamespace: ${project.name}-testing-${local.env.CIRCLE_BUILD_NUM || local.username} + defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username} providers: - name: local-kubernetes environments: [local] diff --git a/garden-service/src/plugins/kubernetes/kubectl.ts b/garden-service/src/plugins/kubernetes/kubectl.ts index 324008be89..349d365ce4 100644 --- a/garden-service/src/plugins/kubernetes/kubectl.ts +++ b/garden-service/src/plugins/kubernetes/kubectl.ts @@ -136,23 +136,19 @@ class Kubectl extends PluginTool { } async stdout(params: KubectlParams) { - this.prepareArgs(params) return super.stdout(params) } async exec(params: KubectlParams) { - this.prepareArgs(params) - return super.exec(params) + return super.exec(this.prepareArgs(params)) } async spawn(params: KubectlParams) { - this.prepareArgs(params) - return super.spawn(params) + return super.spawn(this.prepareArgs(params)) } async spawnAndWait(params: KubectlSpawnParams) { - this.prepareArgs(params) - return super.spawnAndWait(params) + return super.spawnAndWait(this.prepareArgs(params)) } async json(params: KubectlParams): Promise { @@ -168,7 +164,11 @@ class Kubectl extends PluginTool { private prepareArgs(params: KubectlParams) { const { namespace, configPath, args } = params - const opts: string[] = [`--context=${this.provider.config.context}`] + const opts: string[] = [] + + if (this.provider.config.context) { + opts.push(`--context=${this.provider.config.context}`) + } if (this.provider.config.kubeconfig) { opts.push(`--kubeconfig=${this.provider.config.kubeconfig}`) @@ -182,7 +182,7 @@ class Kubectl extends PluginTool { opts.push(`--kubeconfig=${configPath}`) } - params.args = opts.concat(args) + return { ...params, args: opts.concat(args) } } } diff --git a/garden-service/src/plugins/kubernetes/run.ts b/garden-service/src/plugins/kubernetes/run.ts index c9d27bdf60..1fdc75e476 100644 --- a/garden-service/src/plugins/kubernetes/run.ts +++ b/garden-service/src/plugins/kubernetes/run.ts @@ -157,7 +157,7 @@ export async function runAndCopy({ podName: runner.podName, containerNames: [mainContainerName], }) - return containerLogs[0].log + return containerLogs[0]?.log || "" } const timedOutResult = async () => { diff --git a/garden-service/test/integ/src/plugins/kubernetes/container/container.ts b/garden-service/test/integ/src/plugins/kubernetes/container/container.ts index b523e841fd..2e617e7c3d 100644 --- a/garden-service/test/integ/src/plugins/kubernetes/container/container.ts +++ b/garden-service/test/integ/src/plugins/kubernetes/container/container.ts @@ -108,7 +108,7 @@ describe("kubernetes container module handlers", () => { before(async () => { garden = await makeTestGarden(root) provider = await garden.resolveProvider(garden.log, "local-kubernetes") - namespace = garden.projectName + namespace = provider.config.namespace! }) beforeEach(async () => { @@ -161,7 +161,7 @@ describe("kubernetes container module handlers", () => { args: [], interactive: false, module, - namespace: garden.projectName, + namespace: provider.config.namespace!, podName, runtimeContext: { envVars: {}, dependencies: [] }, image, diff --git a/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts b/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts index 6b820f8dfc..c5934bb6d6 100644 --- a/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts +++ b/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts @@ -51,13 +51,14 @@ describe("kubernetes container deployment handlers", () => { it("should create a basic Deployment resource", async () => { const service = graph.getService("simple-service") + const namespace = provider.config.namespace! const resource = await createWorkloadManifest({ api, provider, service, runtimeContext: emptyRuntimeContext, - namespace: garden.projectName, + namespace, enableHotReload: false, log: garden.log, production: false, @@ -71,7 +72,7 @@ describe("kubernetes container deployment handlers", () => { metadata: { name: "simple-service-" + version, annotations: { "garden.io/configured.replicas": "1" }, - namespace: "container", + namespace, labels: { "module": "simple-service", "service": "simple-service", "garden.io/version": version }, }, spec: { @@ -131,7 +132,7 @@ describe("kubernetes container deployment handlers", () => { } await api.upsert({ kind: "Secret", namespace: "default", obj: authSecret, log: garden.log }) - const namespace = garden.projectName + const namespace = provider.config.namespace! const _provider = cloneDeep(provider) _provider.config.imagePullSecrets = [{ name: secretName, namespace: "default" }] @@ -169,7 +170,7 @@ describe("kubernetes container deployment handlers", () => { } await api.upsert({ kind: "Secret", namespace: "default", obj: authSecret, log: garden.log }) - const namespace = garden.projectName + const namespace = provider.config.namespace! const _provider = cloneDeep(provider) _provider.config.imagePullSecrets = [{ name: secretName, namespace: "default" }] @@ -191,7 +192,7 @@ describe("kubernetes container deployment handlers", () => { it("should correctly mount a referenced PVC module", async () => { const service = graph.getService("volume-reference") - const namespace = garden.projectName + const namespace = provider.config.namespace! const resource = await createWorkloadManifest({ api, @@ -212,7 +213,7 @@ describe("kubernetes container deployment handlers", () => { it("should throw if incompatible module is specified as a volume module", async () => { const service = graph.getService("volume-reference") - const namespace = garden.projectName + const namespace = provider.config.namespace! service.spec.volumes = [{ name: "test", module: "simple-service" }] diff --git a/garden-service/test/integ/src/plugins/kubernetes/util.ts b/garden-service/test/integ/src/plugins/kubernetes/util.ts index d5b43dcd31..8a1b82cfcb 100644 --- a/garden-service/test/integ/src/plugins/kubernetes/util.ts +++ b/garden-service/test/integ/src/plugins/kubernetes/util.ts @@ -96,7 +96,7 @@ describe("util", () => { provider, service, runtimeContext: emptyRuntimeContext, - namespace: "container", + namespace: provider.config.namespace!, enableHotReload: false, log: garden.log, production: false,