@@ -217,7 +217,7 @@ export class KubeConfig {
217
217
) ;
218
218
}
219
219
220
- public makeApiClient < T extends ApiType > ( apiClientType : { new ( server : string ) : T } ) {
220
+ public makeApiClient < T extends ApiType > ( apiClientType : ApiConstructor < T > ) {
221
221
const apiClient = new apiClientType ( this . getCurrentCluster ( ) . server ) ;
222
222
apiClient . setDefaultAuthentication ( this ) ;
223
223
@@ -306,7 +306,11 @@ export class KubeConfig {
306
306
}
307
307
308
308
export interface ApiType {
309
- setDefaultAuthentication ( config : KubeConfig ) ;
309
+ setDefaultAuthentication ( config : api . Authentication ) ;
310
+ }
311
+
312
+ export interface ApiConstructor < T extends ApiType > {
313
+ new ( server : string ) : T ;
310
314
}
311
315
312
316
// This class is deprecated and will eventually be removed.
@@ -319,26 +323,36 @@ export class Config {
319
323
Config . SERVICEACCOUNT_ROOT + '/token' ;
320
324
321
325
public static fromFile ( filename : string ) : api . Core_v1Api {
326
+ return Config . apiFromFile ( filename , api . Core_v1Api ) ;
327
+ }
328
+
329
+ public static fromCluster ( ) : api . Core_v1Api {
330
+ return Config . apiFromCluster ( api . Core_v1Api ) ;
331
+ }
332
+
333
+ public static defaultClient ( ) : api . Core_v1Api {
334
+ return Config . apiFromDefaultClient ( api . Core_v1Api ) ;
335
+ }
336
+
337
+ public static apiFromFile < T extends ApiType > ( filename : string , apiClientType : ApiConstructor < T > ) : T {
322
338
const kc = new KubeConfig ( ) ;
323
339
kc . loadFromFile ( filename ) ;
324
-
325
- return kc . makeApiClient ( api . Core_v1Api ) ;
340
+ return kc . makeApiClient ( apiClientType ) ;
326
341
}
327
342
328
- public static fromCluster ( ) : api . Core_v1Api {
343
+ public static apiFromCluster < T extends ApiType > ( apiClientType : ApiConstructor < T > ) : T {
329
344
const kc = new KubeConfig ( ) ;
330
345
kc . loadFromCluster ( ) ;
331
346
332
- const k8sApi = new api . Core_v1Api ( kc . getCurrentCluster ( ) . server ) ;
347
+ const k8sApi = new apiClientType ( kc . getCurrentCluster ( ) . server ) ;
333
348
k8sApi . setDefaultAuthentication ( kc ) ;
334
349
335
350
return k8sApi ;
336
351
}
337
352
338
- public static defaultClient ( ) : api . Core_v1Api {
353
+ public static apiFromDefaultClient < T extends ApiType > ( apiClientType : ApiConstructor < T > ) : T {
339
354
const kc = new KubeConfig ( ) ;
340
355
kc . loadFromDefault ( ) ;
341
-
342
- return kc . makeApiClient ( api . Core_v1Api ) ;
356
+ return kc . makeApiClient ( apiClientType ) ;
343
357
}
344
358
}
0 commit comments