diff --git a/garden-service/src/plugins/kubernetes/kubectl.ts b/garden-service/src/plugins/kubernetes/kubectl.ts index 324008be896..349d365ce46 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 c9d27bdf60b..1fdc75e4767 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 b523e841fd6..8f22fb37115 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 () => { 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 6b820f8dfc9..1a13cee7380 100644 --- a/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts +++ b/garden-service/test/integ/src/plugins/kubernetes/container/deployment.ts @@ -131,7 +131,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 +169,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 +191,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 +212,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" }]