chore: add container statuses to pod (#7524)

This commit is contained in:
Charlie Drage 2024-06-09 11:08:34 -04:00 committed by GitHub
parent 26c41833cd
commit 34d0fb2869
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 0 deletions

View file

@ -44,3 +44,27 @@ test('Renders pod status correctly with hardcoded values', () => {
expect(screen.getByText('Host IP')).toBeInTheDocument();
expect(screen.getByText('192.168.1.2')).toBeInTheDocument();
});
test('show container statuses when present', () => {
const fakePodStatusWithContainers: V1PodStatus = {
phase: 'Running',
containerStatuses: [
{
name: 'container1',
state: {
waiting: {
reason: 'CrashLoopBackOff',
message: 'Back-off restarting failed container',
},
},
},
],
} as V1PodStatus;
render(KubePodStatusArtifact, { artifact: fakePodStatusWithContainers });
expect(screen.getByText('Container Status')).toBeInTheDocument();
expect(screen.getByText('container1')).toBeInTheDocument();
expect(screen.getByText('CrashLoopBackOff')).toBeInTheDocument();
expect(screen.getByText('Back-off restarting failed container')).toBeInTheDocument();
});

View file

@ -2,6 +2,7 @@
import type { V1PodStatus } from '@kubernetes/client-node';
import Cell from './ui/Cell.svelte';
import Subtitle from './ui/Subtitle.svelte';
import Title from './ui/Title.svelte';
export let artifact: V1PodStatus | undefined;
@ -31,4 +32,39 @@ if (artifact?.startTime) {
<Cell>Start Time</Cell>
<Cell>{artifact?.startTime}</Cell>
</tr>
<!-- If containerStatus and at least one in the array has a 'state' that's not undefined.
as the "state" information is where the warning is (unable to pull image, etc.) -->
{#if artifact.containerStatuses?.some(containerStatus => containerStatus.state)}
<tr>
<Title>Container Status</Title>
</tr>
{#each artifact.containerStatuses as containerStatus}
{#if containerStatus.state}
<tr>
<Subtitle>{containerStatus.name}</Subtitle>
</tr>
{#if containerStatus.state.waiting}
<tr>
<Cell>Waiting</Cell>
<Cell>{containerStatus.state.waiting.reason}</Cell>
</tr>
<tr>
<Cell>Message</Cell>
<Cell>{containerStatus.state.waiting.message}</Cell>
</tr>
{/if}
{#if containerStatus.state.terminated}
<tr>
<Cell>Terminated</Cell>
<Cell>{containerStatus.state.terminated.reason}</Cell>
</tr>
<tr>
<Cell>Exit Code</Cell>
<Cell>{containerStatus.state.terminated.exitCode}</Cell>
</tr>
{/if}
{/if}
{/each}
{/if}
{/if}