File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -221,11 +221,17 @@ export class KubeConfig {
221
221
} ,
222
222
} ,
223
223
] ;
224
+ const namespaceFile = `${ pathPrefix } ${ Config . SERVICEACCOUNT_NAMESPACE_PATH } ` ;
225
+ let namespace : string | undefined ;
226
+ if ( fileExists ( namespaceFile ) ) {
227
+ namespace = fs . readFileSync ( namespaceFile , 'utf8' ) ;
228
+ }
224
229
this . contexts = [
225
230
{
226
231
cluster : clusterName ,
227
232
name : contextName ,
228
233
user : userName ,
234
+ namespace,
229
235
} ,
230
236
] ;
231
237
this . currentContext = contextName ;
@@ -448,6 +454,7 @@ export class Config {
448
454
public static SERVICEACCOUNT_ROOT : string = '/var/run/secrets/kubernetes.io/serviceaccount' ;
449
455
public static SERVICEACCOUNT_CA_PATH : string = Config . SERVICEACCOUNT_ROOT + '/ca.crt' ;
450
456
public static SERVICEACCOUNT_TOKEN_PATH : string = Config . SERVICEACCOUNT_ROOT + '/token' ;
457
+ public static SERVICEACCOUNT_NAMESPACE_PATH : string = Config . SERVICEACCOUNT_ROOT + '/namespace' ;
451
458
452
459
public static fromFile ( filename : string ) : api . CoreV1Api {
453
460
return Config . apiFromFile ( filename , api . CoreV1Api ) ;
Original file line number Diff line number Diff line change @@ -1151,10 +1151,12 @@ describe('KubeConfig', () => {
1151
1151
}
1152
1152
const token = 'token' ;
1153
1153
const cert = 'cert' ;
1154
+ const namespace = 'myNamespace' ;
1154
1155
mockfs ( {
1155
1156
'/var/run/secrets/kubernetes.io/serviceaccount' : {
1156
1157
'ca.crt' : cert ,
1157
1158
token,
1159
+ namespace,
1158
1160
} ,
1159
1161
} ) ;
1160
1162
@@ -1181,6 +1183,12 @@ describe('KubeConfig', () => {
1181
1183
'/var/run/secrets/kubernetes.io/serviceaccount/token' ,
1182
1184
) ;
1183
1185
}
1186
+ const contextName = kc . getCurrentContext ( ) ;
1187
+ const currentContext = kc . getContextObject ( contextName ) ;
1188
+ expect ( currentContext ) . to . not . be . null ;
1189
+ if ( currentContext ) {
1190
+ expect ( currentContext . namespace ) . to . equal ( 'myNamespace' ) ;
1191
+ }
1184
1192
} ) ;
1185
1193
1186
1194
it ( 'should load from cluster with http port' , ( ) => {
You can’t perform that action at this time.
0 commit comments