Skip to content

Commit

Permalink
fix: include container name in pod log requests
Browse files Browse the repository at this point in the history
This fixes an occasional issue where deploying services with hot
reloading enabled would fail.
  • Loading branch information
thsig committed Mar 6, 2019
1 parent 8f05156 commit 247272d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion garden-service/src/plugins/kubernetes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,27 @@ async function getPods(api: KubeApi, namespace: string, selector: { [key: string
*/
async function getPodLogs(api: KubeApi, namespace: string, podNames: string[]): Promise<string> {
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) {
Expand Down

0 comments on commit 247272d

Please sign in to comment.