@@ -37,6 +37,7 @@ import { FileContentChangeNotifier, WatchUtil } from './util/watch';
3737import { vsCommand } from './vscommand' ;
3838import { CustomResourceDefinitionStub } from './webview/common/createServiceTypes' ;
3939import { OpenShiftTerminalManager } from './webview/openshift-terminal/openShiftTerminal' ;
40+ import { getOutputFormat , helmfsUri , kubefsUri } from './k8s/vfs/kuberesources.virtualfs' ;
4041
4142type ExplorerItem = KubernetesObject | Helm . HelmRelease | Context | TreeItem | OpenShiftObject | HelmRepo ;
4243
@@ -196,6 +197,11 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
196197 iconPath : element . status === 'failed' ? path . resolve ( __dirname , '../../images/context/helmFailed.svg' ) :
197198 path . resolve ( __dirname , '../../images/context/helmDeployed.svg' ) ,
198199 tooltip : `Chart version: ${ element . chart } \nApp version: ${ element . app_version } \n` ,
200+ command : {
201+ title : 'Load' ,
202+ command : 'openshift.resource.load' ,
203+ arguments : element . status === 'deployed' ? [ element ] : undefined
204+ }
199205 } ;
200206 }
201207
@@ -507,30 +513,56 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
507513 @vsCommand ( 'openshift.resource.load' )
508514 public static async loadResource ( component : KubernetesObject ) {
509515 if ( component ) {
510- if ( component . kind === 'Pod' ) {
511- const contextElement : DeploymentPodObject = component ;
512- const pods = await OpenShiftExplorer . getInstance ( ) . getPods ( contextElement ) ;
513- if ( pods . length === 0 ) {
514- contextElement . status . phase = 'Terminated'
515- void OpenShiftExplorer . getInstance ( ) . refresh ( contextElement ) ;
516- void window . showInformationMessage ( `Pod ${ contextElement . metadata . name } ${ contextElement . status . phase . toLowerCase ( ) } ` ) ;
517- void OpenShiftExplorer . getInstance ( ) . refresh ( ) ;
518- return ;
516+ if ( 'chart' in component && 'name' in component && 'revision' in component
517+ && 'status' in component && component . chart !== 'noChart'
518+ && component . status === 'deployed' ) { // Deployed Helm Chart
519+ const releaseName : string = typeof component . name === 'string' ? component . name : '' ;
520+ const revisionString : string | undefined = typeof component . revision === 'string' ? component . revision : undefined ;
521+ const revision = revisionString ? parseInt ( revisionString , 10 ) : undefined ;
522+ void OpenShiftExplorer . getInstance ( ) . loadKubernetesHelmChart ( releaseName , revision ) ;
523+ } else {
524+ if ( component . kind === 'Pod' ) {
525+ const contextElement : DeploymentPodObject = component ;
526+ const pods = await OpenShiftExplorer . getInstance ( ) . getPods ( contextElement ) ;
527+ if ( pods . length === 0 ) {
528+ contextElement . status . phase = 'Terminated'
529+ void OpenShiftExplorer . getInstance ( ) . refresh ( contextElement ) ;
530+ void window . showInformationMessage ( `Pod ${ contextElement . metadata . name } ${ contextElement . status . phase . toLowerCase ( ) } ` ) ;
531+ void OpenShiftExplorer . getInstance ( ) . refresh ( ) ;
532+ return ;
533+ }
519534 }
535+ void OpenShiftExplorer . getInstance ( ) . loadKubernetesCore ( component . metadata . namespace , `${ component . kind } /${ component . metadata . name } ` ) ;
520536 }
521- void OpenShiftExplorer . getInstance ( ) . loadKubernetesCore ( component . metadata . namespace , `${ component . kind } /${ component . metadata . name } ` ) ;
522537 }
523538 }
524539
525540 /**
526- * loadind deployment config
541+ * Loading deployment config
527542 * @param namespace namespace
528543 * @param value deployment name
529544 */
530545 loadKubernetesCore ( namespace : string | null , value : string ) {
531- const outputFormat = this . getOutputFormat ( ) ;
532- const uri = this . kubefsUri ( namespace , value , outputFormat ) ;
546+ const outputFormat = getOutputFormat ( ) ;
547+ const uri = kubefsUri ( namespace , value , outputFormat ) ;
548+ this . loadKubernetesDocument ( uri ) ;
549+ }
550+
551+ /**
552+ * Loading an installed Helm Chart config
553+ * @param releaseName Installed Helm Chart release name
554+ * @param revision Installed Helm Chart revision
555+ */
556+ loadKubernetesHelmChart ( releaseName : string , revision : number | undefined ) {
557+ const uri = helmfsUri ( releaseName , revision ) ;
558+ this . loadKubernetesDocument ( uri ) ;
559+ }
533560
561+ /**
562+ * Loading a Kubernates document by its Uri
563+ * @param uri A Kubernetes document Uri
564+ */
565+ loadKubernetesDocument ( uri : Uri ) {
534566 const query = this . getComparableQuery ( uri ) ;
535567 const openUri = workspace . textDocuments . map ( ( doc ) => doc . uri )
536568 . find ( ( docUri ) => {
@@ -543,41 +575,15 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
543575
544576 // If open document is found for the URI provided, we use its URI to bring its editor to the front
545577 // instead of openning a new editor
546- workspace . openTextDocument ( openUri ? openUri : uri ) . then ( ( doc ) => {
547- if ( doc ) {
548- void window . showTextDocument ( doc ) ;
549- }
550- } ,
578+ workspace . openTextDocument ( openUri ? openUri : uri ) . then (
579+ ( doc ) => {
580+ if ( doc ) {
581+ void window . showTextDocument ( doc ) ;
582+ }
583+ } ,
551584 ( err ) => window . showErrorMessage ( `Error loading document: ${ err } ` ) ) ;
552585 }
553586
554- /**
555- * get output format from vs-kubernetes.outputFormat
556- * default yaml
557- *
558- * @returns output format
559- */
560- getOutputFormat ( ) : string {
561- if ( workspace . getConfiguration ( 'vs-kubernetes' ) . has ( 'vs-kubernetes.outputFormat' ) ) {
562- return workspace . getConfiguration ( 'vs-kubernetes' ) . get [ 'vs-kubernetes.outputFormat' ] as string ;
563- }
564- return 'yaml'
565- }
566-
567- kubefsUri ( namespace : string | null | undefined , value : string , outputFormat : string , action ?: string ) : Uri {
568- const K8S_RESOURCE_SCHEME = 'k8smsx' ;
569- const K8S_RESOURCE_SCHEME_READONLY = 'k8smsxro' ;
570- const KUBECTL_RESOURCE_AUTHORITY = 'loadkubernetescore' ;
571- const KUBECTL_DESCRIBE_AUTHORITY = 'kubernetesdescribe' ;
572- const docname = `${ value . replace ( '/' , '-' ) } ${ outputFormat && outputFormat !== '' ? `.${ outputFormat } ` : '' } ` ;
573- const nonce = new Date ( ) . getTime ( ) ;
574- const nsquery = namespace ? `ns=${ namespace } &` : '' ;
575- const scheme = action === 'describe' ? K8S_RESOURCE_SCHEME_READONLY : K8S_RESOURCE_SCHEME ;
576- const authority = action === 'describe' ? KUBECTL_DESCRIBE_AUTHORITY : KUBECTL_RESOURCE_AUTHORITY ;
577- const uri = `${ scheme } ://${ authority } /${ docname } ?${ nsquery } value=${ value } &_=${ nonce } ` ;
578- return Uri . parse ( uri ) ;
579- }
580-
581587 /*
582588 * Returns the query string of the specified Uri without "nonce" param,
583589 * so the query strings can be compared.
@@ -640,7 +646,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
640646
641647 @vsCommand ( 'openshift.resource.openInConsole' )
642648 public static openInConsole ( component : KubernetesObject ) {
643- void commands . executeCommand ( 'extension.vsKubernetesLoad ' , { namespace : component . metadata . namespace , kindName : `${ component . kind } /${ component . metadata . name } ` } ) ;
649+ void commands . executeCommand ( 'openshift.resource.load ' , { namespace : component . metadata . namespace , kindName : `${ component . kind } /${ component . metadata . name } ` } ) ;
644650 }
645651
646652 @vsCommand ( 'openshift.explorer.reportIssue' )
0 commit comments