Skip to content

Commit 3d00471

Browse files
committed
feat(config): add argument to preserve context from starting file
1 parent a8d4f1c commit 3d00471

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ export class KubeConfig {
231231
this.currentContext = contextName;
232232
}
233233

234-
public mergeConfig(config: KubeConfig): void {
235-
this.currentContext = config.currentContext;
234+
public mergeConfig(config: KubeConfig, preserveContext: boolean = false): void {
235+
if (!preserveContext) {
236+
this.currentContext = config.currentContext;
237+
}
236238
config.clusters.forEach((cluster: Cluster) => {
237239
this.addCluster(cluster);
238240
});
@@ -280,14 +282,14 @@ export class KubeConfig {
280282
this.contexts.push(ctx);
281283
}
282284

283-
public loadFromDefault(opts?: Partial<ConfigOptions>): void {
285+
public loadFromDefault(opts?: Partial<ConfigOptions>, contextFromStartingConfig: boolean = false): void {
284286
if (process.env.KUBECONFIG && process.env.KUBECONFIG.length > 0) {
285287
const files = process.env.KUBECONFIG.split(path.delimiter);
286288
this.loadFromFile(files[0], opts);
287289
for (let i = 1; i < files.length; i++) {
288290
const kc = new KubeConfig();
289291
kc.loadFromFile(files[i], opts);
290-
this.mergeConfig(kc);
292+
this.mergeConfig(kc, contextFromStartingConfig);
291293
}
292294
return;
293295
}

0 commit comments

Comments
 (0)