@@ -13,6 +13,16 @@ import { CloudAuth } from './cloud_auth';
13
13
import { Cluster , Context , newClusters , newContexts , newUsers , User } from './config_types' ;
14
14
import { ExecAuth } from './exec_auth' ;
15
15
16
+ // fs.existsSync was removed in node 10
17
+ function fileExists ( filepath : string ) : boolean {
18
+ try {
19
+ fs . accessSync ( filepath ) ;
20
+ return true ;
21
+ // tslint:disable-next-line:no-empty
22
+ } catch ( ignore ) { }
23
+ return false ;
24
+ }
25
+
16
26
export class KubeConfig {
17
27
private static authenticators : Authenticator [ ] = [
18
28
new CloudAuth ( ) ,
@@ -197,12 +207,10 @@ export class KubeConfig {
197
207
const home = findHomeDir ( ) ;
198
208
if ( home ) {
199
209
const config = path . join ( home , '.kube' , 'config' ) ;
200
- try {
201
- fs . accessSync ( config ) ;
210
+ if ( fileExists ( config ) ) {
202
211
this . loadFromFile ( config ) ;
203
212
return ;
204
- // tslint:disable-next-line:no-empty
205
- } catch ( ignore ) { }
213
+ }
206
214
}
207
215
if ( process . platform === 'win32' && shelljs . which ( 'wsl.exe' ) ) {
208
216
// TODO: Handle if someome set $KUBECONFIG in wsl here...
@@ -213,12 +221,10 @@ export class KubeConfig {
213
221
}
214
222
}
215
223
216
- try {
217
- fs . accessSync ( Config . SERVICEACCOUNT_TOKEN_PATH ) ;
224
+ if ( fileExists ( Config . SERVICEACCOUNT_TOKEN_PATH ) ) {
218
225
this . loadFromCluster ( ) ;
219
226
return ;
220
- // tslint:disable-next-line:no-empty
221
- } catch ( ignore ) { }
227
+ }
222
228
223
229
this . loadFromClusterAndUser (
224
230
{ name : 'cluster' , server : 'http://localhost:8080' } as Cluster ,
0 commit comments