Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 15003b3

Browse files
committed
feat: Containers kube tab
1 parent 3d55061 commit 15003b3

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

plugins/plugin-kubectl/src/lib/model/resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface KubeStatusCondition {
3232
phase?: string
3333
}
3434

35-
interface KubeContainerStatus {
35+
export interface KubeContainerStatus {
3636
name: string
3737
containerID: string
3838
restartCount: number
@@ -304,7 +304,7 @@ interface ContainerSpec {
304304
image: string
305305
imagePullPolicy: string
306306
name: string
307-
resource: Record<string, any> // eslint-disable-line @typescript-eslint/no-explicit-any
307+
resources: Record<string, unknown>
308308
terminationMessagePath: string
309309
terminationMessagePolicy: string
310310
volumeMounts: { mountPath: string; name: string }[]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2023 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type { ModeRegistration, Tab } from '@kui-shell/core'
18+
19+
import { KubeContainerStatus, Pod, isPod } from '../../model/resource'
20+
21+
async function content(_: Tab, resource: Pod) {
22+
// this module is expensive to load, so we defer that expense
23+
const { dump } = await import('js-yaml')
24+
25+
// helps with unified just below
26+
const statuses = resource.status.containerStatuses.reduce((M, _) => {
27+
const status = Object.assign({}, _)
28+
delete status.name // no need to say this twice, once for spec, once for status
29+
M[_.name] = status
30+
return M
31+
}, {} as Record<string, KubeContainerStatus>)
32+
33+
// unify spec and status
34+
const unified = resource.spec.containers.reduce((M, _) => {
35+
const combo = Object.assign(
36+
{
37+
args: _.args,
38+
resources: _.resources,
39+
status: statuses[_.name] || 'missing status'
40+
},
41+
_
42+
)
43+
delete combo.name
44+
M[_.name] = combo
45+
return M
46+
}, {})
47+
48+
return {
49+
contentType: 'yaml',
50+
content: dump(unified)
51+
}
52+
}
53+
54+
/**
55+
* The Summary mode applies to all KubeResources, and uses
56+
* `renderContent` to render the view.
57+
*
58+
*/
59+
const logsReg: ModeRegistration<Pod> = {
60+
when: isPod,
61+
mode: {
62+
mode: 'containers',
63+
label: 'Containers',
64+
content
65+
}
66+
}
67+
68+
export default logsReg

plugins/plugin-kubectl/src/lib/view/modes/yaml.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ async function content(_, resource: WithRawData) {
3939
content: dump(
4040
JSON.parse(
4141
JSON.stringify(load(resource.kuiRawData), (key, value) =>
42-
key === 'managedFields' || key === 'annotations' /* || key === 'labels' */ ? undefined : value
42+
key === 'managedFields' ||
43+
key === 'annotations' ||
44+
key === 'containers' ||
45+
key === 'containerStatuses' /* || key === 'labels' */
46+
? undefined
47+
: value
4348
)
4449
)
4550
)

plugins/plugin-kubectl/src/non-headless-preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import yamlMode from './lib/view/modes/yaml'
2323
import summaryMode from './lib/view/modes/Summary'
2424
import crdSummaryMode from './lib/view/modes/crd-summary'
2525
import configmapSummaryMode from './lib/view/modes/configmap-summary'
26+
import containersMode from './lib/view/modes/Containers'
2627
import logsMode from './lib/view/modes/logs-mode'
2728
import ExecIntoPad from './lib/view/modes/ExecIntoPod'
2829
import lastAppliedMode from './lib/view/modes/last-applied'
@@ -58,6 +59,7 @@ export default async (registrar: PreloadRegistrar) => {
5859
logsMode,
5960
ExecIntoPad,
6061
lastAppliedMode,
62+
containersMode,
6163
EditButton,
6264
// managedFieldsMode,
6365
showCRDResources,

0 commit comments

Comments
 (0)