From 247272d4ffebb27438a62ea0e6370dc5c2414e82 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Tue, 5 Mar 2019 19:54:23 +0100 Subject: [PATCH] fix: include container name in pod log requests This fixes an occasional issue where deploying services with hot reloading enabled would fail. --- .../src/plugins/kubernetes/status.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/garden-service/src/plugins/kubernetes/status.ts b/garden-service/src/plugins/kubernetes/status.ts index c520948f7b..9be2890f5e 100644 --- a/garden-service/src/plugins/kubernetes/status.ts +++ b/garden-service/src/plugins/kubernetes/status.ts @@ -565,11 +565,27 @@ async function getPods(api: KubeApi, namespace: string, selector: { [key: string */ async function getPodLogs(api: KubeApi, namespace: string, podNames: string[]): Promise { const allLogs = await Bluebird.map(podNames, async (name) => { + let containerName: string | undefined + try { + const podRes = await api.core.readNamespacedPod(name, namespace) + const containerNames = podRes.body.spec.containers.map(c => c.name) + if (containerNames.length > 1) { + containerName = containerNames.filter(n => !n.match(/garden-/))[0] + } else { + containerName = undefined + } + } catch (err) { + if (err.code === 404) { + return "" + } else { + throw err + } + } // Putting 5000 bytes as a length limit in addition to the line limit, just as a precaution in case someone // accidentally logs a binary file or something. try { const res = await api.core.readNamespacedPodLog( - name, namespace, undefined, false, 5000, undefined, false, undefined, podLogLines, + name, namespace, containerName, false, 5000, undefined, false, undefined, podLogLines, ) return res.body ? `****** ${name} ******\n${res.body}` : "" } catch (err) {