@@ -71,27 +71,27 @@ export class KubeConfig {
71
71
this . users = [ ] ;
72
72
}
73
73
74
- public getContexts ( ) {
74
+ public getContexts ( ) : Context [ ] {
75
75
return this . contexts ;
76
76
}
77
77
78
- public getClusters ( ) {
78
+ public getClusters ( ) : Cluster [ ] {
79
79
return this . clusters ;
80
80
}
81
81
82
- public getUsers ( ) {
82
+ public getUsers ( ) : User [ ] {
83
83
return this . users ;
84
84
}
85
85
86
- public getCurrentContext ( ) {
86
+ public getCurrentContext ( ) : string {
87
87
return this . currentContext ;
88
88
}
89
89
90
- public setCurrentContext ( context : string ) {
90
+ public setCurrentContext ( context : string ) : void {
91
91
this . currentContext = context ;
92
92
}
93
93
94
- public getContextObject ( name : string ) {
94
+ public getContextObject ( name : string ) : Context | null {
95
95
if ( ! this . contexts ) {
96
96
return null ;
97
97
}
@@ -122,13 +122,13 @@ export class KubeConfig {
122
122
return findObject ( this . users , name , 'user' ) ;
123
123
}
124
124
125
- public loadFromFile ( file : string , opts ?: Partial < ConfigOptions > ) {
125
+ public loadFromFile ( file : string , opts ?: Partial < ConfigOptions > ) : void {
126
126
const rootDirectory = path . dirname ( file ) ;
127
127
this . loadFromString ( fs . readFileSync ( file , 'utf8' ) , opts ) ;
128
128
this . makePathsAbsolute ( rootDirectory ) ;
129
129
}
130
130
131
- public async applytoHTTPSOptions ( opts : https . RequestOptions ) {
131
+ public async applytoHTTPSOptions ( opts : https . RequestOptions ) : Promise < void > {
132
132
const user = this . getCurrentUser ( ) ;
133
133
134
134
await this . applyOptions ( opts ) ;
@@ -138,7 +138,7 @@ export class KubeConfig {
138
138
}
139
139
}
140
140
141
- public async applyToRequest ( opts : request . Options ) {
141
+ public async applyToRequest ( opts : request . Options ) : Promise < void > {
142
142
const cluster = this . getCurrentCluster ( ) ;
143
143
const user = this . getCurrentUser ( ) ;
144
144
@@ -156,22 +156,22 @@ export class KubeConfig {
156
156
}
157
157
}
158
158
159
- public loadFromString ( config : string , opts ?: Partial < ConfigOptions > ) {
159
+ public loadFromString ( config : string , opts ?: Partial < ConfigOptions > ) : void {
160
160
const obj = yaml . safeLoad ( config ) ;
161
161
this . clusters = newClusters ( obj . clusters , opts ) ;
162
162
this . contexts = newContexts ( obj . contexts , opts ) ;
163
163
this . users = newUsers ( obj . users , opts ) ;
164
164
this . currentContext = obj [ 'current-context' ] ;
165
165
}
166
166
167
- public loadFromOptions ( options : any ) {
167
+ public loadFromOptions ( options : any ) : void {
168
168
this . clusters = options . clusters ;
169
169
this . contexts = options . contexts ;
170
170
this . users = options . users ;
171
171
this . currentContext = options . currentContext ;
172
172
}
173
173
174
- public loadFromClusterAndUser ( cluster : Cluster , user : User ) {
174
+ public loadFromClusterAndUser ( cluster : Cluster , user : User ) : void {
175
175
this . clusters = [ cluster ] ;
176
176
this . users = [ user ] ;
177
177
this . currentContext = 'loaded-context' ;
@@ -184,7 +184,7 @@ export class KubeConfig {
184
184
] ;
185
185
}
186
186
187
- public loadFromCluster ( pathPrefix : string = '' ) {
187
+ public loadFromCluster ( pathPrefix : string = '' ) : void {
188
188
const host = process . env . KUBERNETES_SERVICE_HOST ;
189
189
const port = process . env . KUBERNETES_SERVICE_PORT ;
190
190
const clusterName = 'inCluster' ;
@@ -231,7 +231,7 @@ export class KubeConfig {
231
231
this . currentContext = contextName ;
232
232
}
233
233
234
- public mergeConfig ( config : KubeConfig ) {
234
+ public mergeConfig ( config : KubeConfig ) : void {
235
235
this . currentContext = config . currentContext ;
236
236
config . clusters . forEach ( ( cluster : Cluster ) => {
237
237
this . addCluster ( cluster ) ;
@@ -244,7 +244,7 @@ export class KubeConfig {
244
244
} ) ;
245
245
}
246
246
247
- public addCluster ( cluster : Cluster ) {
247
+ public addCluster ( cluster : Cluster ) : void {
248
248
if ( ! this . clusters ) {
249
249
this . clusters = [ ] ;
250
250
}
@@ -256,7 +256,7 @@ export class KubeConfig {
256
256
this . clusters . push ( cluster ) ;
257
257
}
258
258
259
- public addUser ( user : User ) {
259
+ public addUser ( user : User ) : void {
260
260
if ( ! this . users ) {
261
261
this . users = [ ] ;
262
262
}
@@ -268,7 +268,7 @@ export class KubeConfig {
268
268
this . users . push ( user ) ;
269
269
}
270
270
271
- public addContext ( ctx : Context ) {
271
+ public addContext ( ctx : Context ) : void {
272
272
if ( ! this . contexts ) {
273
273
this . contexts = [ ] ;
274
274
}
@@ -280,7 +280,7 @@ export class KubeConfig {
280
280
this . contexts . push ( ctx ) ;
281
281
}
282
282
283
- public loadFromDefault ( opts ?: Partial < ConfigOptions > ) {
283
+ public loadFromDefault ( opts ?: Partial < ConfigOptions > ) : void {
284
284
if ( process . env . KUBECONFIG && process . env . KUBECONFIG . length > 0 ) {
285
285
const files = process . env . KUBECONFIG . split ( path . delimiter ) ;
286
286
this . loadFromFile ( files [ 0 ] , opts ) ;
@@ -323,7 +323,7 @@ export class KubeConfig {
323
323
) ;
324
324
}
325
325
326
- public makeApiClient < T extends ApiType > ( apiClientType : ApiConstructor < T > ) {
326
+ public makeApiClient < T extends ApiType > ( apiClientType : ApiConstructor < T > ) : T {
327
327
const cluster = this . getCurrentCluster ( ) ;
328
328
if ( ! cluster ) {
329
329
throw new Error ( 'No active cluster!' ) ;
@@ -334,7 +334,7 @@ export class KubeConfig {
334
334
return apiClient ;
335
335
}
336
336
337
- public makePathsAbsolute ( rootDirectory : string ) {
337
+ public makePathsAbsolute ( rootDirectory : string ) : void {
338
338
this . clusters . forEach ( ( cluster : Cluster ) => {
339
339
if ( cluster . caFile ) {
340
340
cluster . caFile = makeAbsolutePath ( rootDirectory , cluster . caFile ) ;
@@ -364,11 +364,11 @@ export class KubeConfig {
364
364
return JSON . stringify ( configObj ) ;
365
365
}
366
366
367
- private getCurrentContextObject ( ) {
367
+ private getCurrentContextObject ( ) : Context | null {
368
368
return this . getContextObject ( this . currentContext ) ;
369
369
}
370
370
371
- private applyHTTPSOptions ( opts : request . Options | https . RequestOptions ) {
371
+ private applyHTTPSOptions ( opts : request . Options | https . RequestOptions ) : void {
372
372
const cluster = this . getCurrentCluster ( ) ;
373
373
const user = this . getCurrentUser ( ) ;
374
374
if ( ! user ) {
@@ -392,7 +392,7 @@ export class KubeConfig {
392
392
}
393
393
}
394
394
395
- private async applyAuthorizationHeader ( opts : request . Options | https . RequestOptions ) {
395
+ private async applyAuthorizationHeader ( opts : request . Options | https . RequestOptions ) : Promise < void > {
396
396
const user = this . getCurrentUser ( ) ;
397
397
if ( ! user ) {
398
398
return ;
@@ -413,7 +413,7 @@ export class KubeConfig {
413
413
}
414
414
}
415
415
416
- private async applyOptions ( opts : request . Options | https . RequestOptions ) {
416
+ private async applyOptions ( opts : request . Options | https . RequestOptions ) : Promise < void > {
417
417
this . applyHTTPSOptions ( opts ) ;
418
418
await this . applyAuthorizationHeader ( opts ) ;
419
419
}
@@ -428,9 +428,9 @@ type ApiConstructor<T extends ApiType> = new (server: string) => T;
428
428
429
429
// This class is deprecated and will eventually be removed.
430
430
export class Config {
431
- public static SERVICEACCOUNT_ROOT = '/var/run/secrets/kubernetes.io/serviceaccount' ;
432
- public static SERVICEACCOUNT_CA_PATH = Config . SERVICEACCOUNT_ROOT + '/ca.crt' ;
433
- public static SERVICEACCOUNT_TOKEN_PATH = Config . SERVICEACCOUNT_ROOT + '/token' ;
431
+ public static SERVICEACCOUNT_ROOT : string = '/var/run/secrets/kubernetes.io/serviceaccount' ;
432
+ public static SERVICEACCOUNT_CA_PATH : string = Config . SERVICEACCOUNT_ROOT + '/ca.crt' ;
433
+ public static SERVICEACCOUNT_TOKEN_PATH : string = Config . SERVICEACCOUNT_ROOT + '/token' ;
434
434
435
435
public static fromFile ( filename : string ) : api . CoreV1Api {
436
436
return Config . apiFromFile ( filename , api . CoreV1Api ) ;
0 commit comments