@@ -24,14 +24,12 @@ import {
24
24
import * as Helm from './helm/helm' ;
25
25
import { Oc } from './oc/ocWrapper' ;
26
26
import { Odo } from './odo/odoWrapper' ;
27
- import { KubeConfigUtils } from './util/kubeUtils' ;
27
+ import { KubeConfigUtils , getKubeConfigFiles } from './util/kubeUtils' ;
28
28
import { Platform } from './util/platform' ;
29
29
import { Progress } from './util/progress' ;
30
30
import { FileContentChangeNotifier , WatchUtil } from './util/watch' ;
31
31
import { vsCommand } from './vscommand' ;
32
32
33
- const kubeConfigFolder : string = path . join ( Platform . getUserHomePath ( ) , '.kube' ) ;
34
-
35
33
type ExplorerItem = KubernetesObject | Helm . HelmRelease | Context | TreeItem ;
36
34
37
35
type PackageJSON = {
@@ -42,7 +40,7 @@ type PackageJSON = {
42
40
const CREATE_OR_SET_PROJECT_ITEM = {
43
41
label : 'Create new or set active Project' ,
44
42
command : {
45
- title : 'Create new or ser active Project' ,
43
+ title : 'Create new or set active Project' ,
46
44
command : 'openshift.project.set'
47
45
}
48
46
} ;
@@ -52,7 +50,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
52
50
53
51
private treeView : TreeView < ExplorerItem > ;
54
52
55
- private fsw : FileContentChangeNotifier ;
53
+ private kubeConfigWatchers : FileContentChangeNotifier [ ] ;
56
54
private kubeContext : Context ;
57
55
private kubeConfig : KubeConfigUtils ;
58
56
@@ -70,22 +68,25 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
70
68
// ignore config loading error and let odo report it on first call
71
69
}
72
70
try {
73
- this . fsw = WatchUtil . watchFileForContextChange ( kubeConfigFolder , 'config' ) ;
71
+ const kubeconfigFiles = getKubeConfigFiles ( ) ;
72
+ this . kubeConfigWatchers = kubeconfigFiles . map ( kubeconfigFile => WatchUtil . watchFileForContextChange ( path . dirname ( kubeconfigFile ) , path . basename ( kubeconfigFile ) ) ) ;
74
73
} catch ( err ) {
75
74
void window . showWarningMessage ( 'Couldn\'t install watcher for Kubernetes configuration file. OpenShift Application Explorer view won\'t be updated automatically.' ) ;
76
75
}
77
- this . fsw ?. emitter ?. on ( 'file-changed' , ( ) => {
78
- const ku2 = new KubeConfigUtils ( ) ;
79
- const newCtx = ku2 . getContextObject ( ku2 . currentContext ) ;
80
- if ( ! this . kubeContext
81
- || ( this . kubeContext . cluster !== newCtx . cluster
82
- || this . kubeContext . user !== newCtx . user
83
- || this . kubeContext . namespace !== newCtx . namespace ) ) {
84
- this . refresh ( ) ;
85
- }
86
- this . kubeContext = newCtx ;
87
- this . kubeConfig = ku2 ;
88
- } ) ;
76
+ for ( const fsw of this . kubeConfigWatchers ) {
77
+ fsw . emitter ?. on ( 'file-changed' , ( ) => {
78
+ const ku2 = new KubeConfigUtils ( ) ;
79
+ const newCtx = ku2 . getContextObject ( ku2 . currentContext ) ;
80
+ if ( Boolean ( this . kubeContext ) !== Boolean ( newCtx )
81
+ || ( this . kubeContext . cluster !== newCtx . cluster
82
+ || this . kubeContext . user !== newCtx . user
83
+ || this . kubeContext . namespace !== newCtx . namespace ) ) {
84
+ this . refresh ( ) ;
85
+ }
86
+ this . kubeContext = newCtx ;
87
+ this . kubeConfig = ku2 ;
88
+ } ) ;
89
+ }
89
90
this . treeView = window . createTreeView < ExplorerItem > ( 'openshiftProjectExplorer' , {
90
91
treeDataProvider : this ,
91
92
} ) ;
@@ -110,7 +111,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
110
111
contextValue : 'openshift.openConfigFile' ,
111
112
label : element . label ,
112
113
collapsibleState : TreeItemCollapsibleState . None ,
113
- tooltip : 'Default KubeConfig' ,
114
+ tooltip : element . label as string ,
114
115
description : element . description ,
115
116
iconPath : new ThemeIcon ( 'file' )
116
117
} ;
@@ -175,11 +176,8 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
175
176
await Odo . Instance . getProjects ( ) ;
176
177
result = [ this . kubeContext ] ;
177
178
if ( this . kubeContext ) {
178
- const homeDir = this . kubeConfig . findHomeDir ( ) ;
179
- if ( homeDir ) {
180
- const config = path . join ( homeDir , '.kube' , 'config' ) ;
181
- result . unshift ( { label : 'Default KubeConfig' , description : `${ config } ` } )
182
- }
179
+ const config = getKubeConfigFiles ( ) ;
180
+ result . unshift ( { label : process . env . KUBECONFIG ? 'Custom KubeConfig' : 'Default KubeConfig' , description : config . join ( ':' ) } )
183
181
}
184
182
} catch ( err ) {
185
183
// ignore because ether server is not accessible or user is logged out
@@ -246,7 +244,9 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
246
244
}
247
245
248
246
dispose ( ) : void {
249
- this . fsw ?. watcher ?. close ( ) ;
247
+ for ( const fsw of this . kubeConfigWatchers ) {
248
+ fsw ?. watcher ?. close ( ) ;
249
+ }
250
250
this . treeView . dispose ( ) ;
251
251
}
252
252
0 commit comments