From 3e3370822ca0c241c7f4552a26e8a21e54a2ad41 Mon Sep 17 00:00:00 2001 From: zbarnes Date: Mon, 28 Sep 2020 13:47:43 -0500 Subject: [PATCH] Issue 49: Add logs for init containers --- client/src/utils/types.ts | 1 + client/src/views/logs.tsx | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/client/src/utils/types.ts b/client/src/utils/types.ts index ed4db6d..26134fb 100644 --- a/client/src/utils/types.ts +++ b/client/src/utils/types.ts @@ -116,6 +116,7 @@ interface ContainerStatus { interface PodSpec { nodeName: string; containers: Container[]; + initContainers?: Container[]; nodeSelector?: {[key: string]: string}; } diff --git a/client/src/views/logs.tsx b/client/src/views/logs.tsx index c82840a..d7cdc0c 100644 --- a/client/src/views/logs.tsx +++ b/client/src/views/logs.tsx @@ -21,6 +21,7 @@ type State = { item?: Pod; containers?: string[]; container?: string; + initContainers?: string[]; filter?: string; } @@ -52,7 +53,14 @@ export default class Logs extends Base { onPod(pod: Pod) { const containers = pod.spec.containers.map(x => x.name); - this.setState({containers}); + let initContainers: string[] = []; + + if (pod.spec.initContainers) { + initContainers = pod.spec.initContainers.map(x => x.name); + } + + + this.setState({containers, initContainers }); this.setContainer(containers[0]); } @@ -79,13 +87,23 @@ export default class Logs extends Base { render() { const {namespace, name} = this.props; - const {items, container, containers = [], filter = '', showPrevious = false} = this.state; + const {items, container, containers = [], initContainers = [], filter = '', showPrevious = false} = this.state; const lowercaseFilter = filter.toLowerCase(); const filteredLogs = items.filter(x => x.toLowerCase().includes(lowercaseFilter)); - const options = containers.map(x => ({value: x, label: x})); - const selected = options.find(x => x.value === container); + const containerOptions = containers.map(x => ({ value: x, label: x })); + const initContainerOptions = initContainers.map(x => ({ value: x, label: x })); + + const options = [{ + label: 'Containers', + options: containerOptions + }, { + label: 'Init Containers', + options: initContainerOptions + }]; + + const selected = [...containerOptions, ...initContainerOptions].find((x) => x.value == container); return (