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

Commit 7c8cdea

Browse files
committed
feat: improve helm drilldown view
Show managed resources and values, and offer a drilldown to managed resources.
1 parent 15003b3 commit 7c8cdea

File tree

3 files changed

+56
-51
lines changed

3 files changed

+56
-51
lines changed

plugins/plugin-kubectl/helm/src/controller/helm/status.ts

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import Debug from 'debug'
18-
import { Arguments, DescriptionList, ExecOptions, Registrar, Menu, NavResponse, i18n } from '@kui-shell/core'
18+
import { Arguments, DescriptionList, Registrar, MultiModalResponse, i18n } from '@kui-shell/core'
1919
import { doHelp, withKubeconfigFrom, KubeOptions } from '@kui-shell/plugin-kubectl'
2020

2121
import isUsage from './usage'
@@ -32,15 +32,11 @@ const debug = Debug('plugin-kubectl/helm/controller/helm/status')
3232
export const format = async (
3333
name: string,
3434
args: Arguments<KubeOptions>,
35-
response: string,
36-
execOptions: ExecOptions
37-
): Promise<NavResponse> => {
38-
const command = 'kubectl'
39-
const verb = 'get'
40-
41-
debug('nested?', execOptions.nested)
42-
debug('command', command)
43-
debug('verb', verb)
35+
response: string
36+
): Promise<MultiModalResponse> => {
37+
// start fetching the associated resources
38+
const resourcesP = args.REPL.qexec<string>(withKubeconfigFrom(args, `helm get manifest ${name}`, 'kube-context'))
39+
const valuesP = args.REPL.qexec<string>(withKubeconfigFrom(args, `helm get values ${name}`, 'kube-context'))
4440

4541
const [headerString] = response.split(/RESOURCES:|(?=NOTES:)/)
4642

@@ -52,8 +48,12 @@ export const format = async (
5248
const revisionFromHelmStatusOutput = revisionMatch[1]
5349
debug('revision', revisionFromHelmStatusOutput)
5450

51+
// -l app.kubernetes.io/managed-by: Helm
52+
// meta.helm.sh/release-name: ray-myapp-7820e072-7e3e-4b46-829e-28a4a28a7457
53+
54+
// Status description list
5555
const statusMatch = headerString.match(/LAST DEPLOYED: (.*)\nNAMESPACE: (.*)\nSTATUS: (.*)/)
56-
const status: DescriptionList = {
56+
const statusDL: DescriptionList = {
5757
apiVersion: 'kui-shell/v1',
5858
kind: 'DescriptionList',
5959
spec: {
@@ -64,51 +64,48 @@ export const format = async (
6464
]
6565
}
6666
}
67+
const status = {
68+
mode: 'Status',
69+
content: statusDL
70+
}
6771

68-
const summary = ''
69-
70-
const notesMatch = response.match(/NOTES:\n([\s\S]+)?/)
71-
const notes = notesMatch && notesMatch[1]
72-
73-
const overviewMenu: Menu = {
74-
label: 'Overview',
75-
items: []
72+
const resources = {
73+
mode: 'Managed Resources',
74+
contentType: 'yaml',
75+
content: (await resourcesP).replace(/^\s*---\s+/, '')
7676
}
7777

78-
overviewMenu.items.push({
79-
mode: 'status',
80-
label: strings('status'),
81-
content: status
82-
})
83-
84-
if (summary) {
85-
overviewMenu.items.push({
86-
mode: 'summary',
87-
label: strings('summary'),
88-
content: summary,
89-
contentType: 'text/markdown'
90-
})
78+
const values = {
79+
mode: 'Values',
80+
contentType: 'yaml',
81+
content: (await valuesP).replace(/^\s*USER-SUPPLIED VALUES:\s+/, '')
9182
}
9283

93-
if (notes) {
94-
overviewMenu.items.push({
95-
mode: 'notes',
96-
label: strings2('Notes'),
97-
content: `\`\`\`${notes}\`\`\``,
98-
contentType: 'text/markdown'
99-
})
84+
const drilldown = {
85+
mode: 'Show Managed Resources',
86+
kind: 'drilldown' as const,
87+
showRelatedResource: true,
88+
command: withKubeconfigFrom(
89+
args,
90+
`kubectl get all -l app.kubernetes.io/managed-by=Helm,app.kubernetes.io/name=${name}`
91+
)
10092
}
10193

102-
return {
94+
const mmr: MultiModalResponse = {
10395
apiVersion: 'kui-shell/v1',
104-
kind: 'NavResponse',
105-
breadcrumbs: [
106-
{ label: 'helm' },
107-
{ label: 'release', command: withKubeconfigFrom(args, `helm ls`) },
108-
{ label: name }
109-
],
110-
menus: [overviewMenu]
96+
kind: 'HelmChart',
97+
metadata: {
98+
name
99+
},
100+
onclick: {
101+
kind: withKubeconfigFrom(args, 'helm ls', 'kube-context'),
102+
name: withKubeconfigFrom(args, `helm ls ${name}`, 'kube-context')
103+
},
104+
buttons: [drilldown],
105+
modes: [status, resources, values]
111106
}
107+
108+
return mmr
112109
}
113110

114111
async function doStatus(args: Arguments<KubeOptions>) {
@@ -120,7 +117,7 @@ async function doStatus(args: Arguments<KubeOptions>) {
120117
const response = await doExecWithStdout(args)
121118

122119
try {
123-
return format(name, args, response, args.execOptions)
120+
return format(name, args, response)
124121
} catch (err) {
125122
console.error('error formatting status', err)
126123
return response

plugins/plugin-kubectl/helm/src/test/helm/helm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe(`helm commands ${process.env.MOCHA_RUN_TARGET || ''}`, function (this:
6363
const checkHelmInstall = async (res: ReplExpect.AppAndCount) => {
6464
await ReplExpect.ok(res)
6565
await SidecarExpect.open(res)
66-
await SidecarExpect.showingLeftNav('Overview')(res)
66+
await SidecarExpect.showing(name)(res)
6767
}
6868

6969
it('should update the helm repo to add bitnami', () => {

plugins/plugin-kubectl/src/controller/kubectl/options.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,23 @@ export function isForAllNamespaces(parsedOptions: KubeOptions) {
330330
}
331331

332332
/** Copy over any kubeconfig/context/cluster/namespace specifications from the given args */
333-
export function withKubeconfigFrom(args: Pick<Arguments<KubeOptions>, 'parsedOptions'>, cmdline: string): string {
333+
export function withKubeconfigFrom(
334+
args: Pick<Arguments<KubeOptions>, 'parsedOptions'>,
335+
cmdline: string,
336+
context = 'context'
337+
): string {
334338
let extras = ' '
335339

336340
if (args.parsedOptions.kubeconfig && !/--kubeconfig/.test(cmdline)) {
337341
extras += ` --kubeconfig ${Util.expandHomeDir(args.parsedOptions.kubeconfig)}`
338342
}
339343

340344
if (args.parsedOptions.context && !/--context/.test(cmdline)) {
341-
extras += ` --context ${args.parsedOptions.context}`
345+
extras += ` --${context} ${args.parsedOptions.context}`
346+
}
347+
348+
if (args.parsedOptions.context && !/--kube-context/.test(cmdline)) {
349+
extras += ` --${context} ${args.parsedOptions.context}`
342350
}
343351

344352
if (args.parsedOptions.cluster && !/--cluster/.test(cmdline)) {

0 commit comments

Comments
 (0)