15
15
*/
16
16
17
17
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'
19
19
import { doHelp , withKubeconfigFrom , KubeOptions } from '@kui-shell/plugin-kubectl'
20
20
21
21
import isUsage from './usage'
@@ -32,15 +32,11 @@ const debug = Debug('plugin-kubectl/helm/controller/helm/status')
32
32
export const format = async (
33
33
name : string ,
34
34
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' ) )
44
40
45
41
const [ headerString ] = response . split ( / R E S O U R C E S : | (? = N O T E S : ) / )
46
42
@@ -52,8 +48,12 @@ export const format = async (
52
48
const revisionFromHelmStatusOutput = revisionMatch [ 1 ]
53
49
debug ( 'revision' , revisionFromHelmStatusOutput )
54
50
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
55
55
const statusMatch = headerString . match ( / L A S T D E P L O Y E D : ( .* ) \n N A M E S P A C E : ( .* ) \n S T A T U S : ( .* ) / )
56
- const status : DescriptionList = {
56
+ const statusDL : DescriptionList = {
57
57
apiVersion : 'kui-shell/v1' ,
58
58
kind : 'DescriptionList' ,
59
59
spec : {
@@ -64,51 +64,48 @@ export const format = async (
64
64
]
65
65
}
66
66
}
67
+ const status = {
68
+ mode : 'Status' ,
69
+ content : statusDL
70
+ }
67
71
68
- const summary = ''
69
-
70
- const notesMatch = response . match ( / N O T E S : \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 + / , '' )
76
76
}
77
77
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 * U S E R - S U P P L I E D V A L U E S : \s + / , '' )
91
82
}
92
83
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
+ )
100
92
}
101
93
102
- return {
94
+ const mmr : MultiModalResponse = {
103
95
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 ]
111
106
}
107
+
108
+ return mmr
112
109
}
113
110
114
111
async function doStatus ( args : Arguments < KubeOptions > ) {
@@ -120,7 +117,7 @@ async function doStatus(args: Arguments<KubeOptions>) {
120
117
const response = await doExecWithStdout ( args )
121
118
122
119
try {
123
- return format ( name , args , response , args . execOptions )
120
+ return format ( name , args , response )
124
121
} catch ( err ) {
125
122
console . error ( 'error formatting status' , err )
126
123
return response
0 commit comments