File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change @@ -326,23 +326,11 @@ export class Config {
326
326
}
327
327
328
328
public static fromCluster ( ) : api . Core_v1Api {
329
- const host = process . env . KUBERNETES_SERVICE_HOST ;
330
- const port = process . env . KUBERNETES_SERVICE_PORT ;
331
-
332
- // TODO: better error checking here.
333
- const caCert = fs . readFileSync ( Config . SERVICEACCOUNT_CA_PATH ) ;
334
- const token = fs . readFileSync ( Config . SERVICEACCOUNT_TOKEN_PATH ) ;
329
+ const kc = new KubeConfig ( ) ;
330
+ kc . loadFromCluster ( ) ;
335
331
336
- const k8sApi = new api . Core_v1Api ( 'https://' + host + ':' + port ) ;
337
- k8sApi . setDefaultAuthentication ( {
338
- applyToRequest : ( opts ) => {
339
- opts . ca = caCert ;
340
- if ( ! opts . headers ) {
341
- opts . headers = [ ] ;
342
- }
343
- opts . headers . Authorization = 'Bearer ' + token ;
344
- } ,
345
- } ) ;
332
+ const k8sApi = new api . Core_v1Api ( kc . getCurrentCluster ( ) . server ) ;
333
+ k8sApi . setDefaultAuthentication ( kc ) ;
346
334
347
335
return k8sApi ;
348
336
}
You can’t perform that action at this time.
0 commit comments