Skip to content

Commit 9004445

Browse files
committed
Added filtering of empty paths in KUBECONFIG
1 parent 7f3bbfd commit 9004445

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class KubeConfig {
284284

285285
public loadFromDefault(opts?: Partial<ConfigOptions>, contextFromStartingConfig: boolean = false): void {
286286
if (process.env.KUBECONFIG && process.env.KUBECONFIG.length > 0) {
287-
const files = process.env.KUBECONFIG.split(path.delimiter);
287+
const files = process.env.KUBECONFIG.split(path.delimiter).filter((filename: string) => filename);
288288
this.loadFromFile(files[0], opts);
289289
for (let i = 1; i < files.length; i++) {
290290
const kc = new KubeConfig();

src/config_test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,18 @@ describe('KubeConfig', () => {
10641064
const kc = new KubeConfig();
10651065
expect(() => kc.loadFromDefault()).to.throw('Duplicate user: user1');
10661066
});
1067+
1068+
it('should ignore extra path delimiters', () => {
1069+
process.env.KUBECONFIG = path.delimiter + kcFileName + path.delimiter;
1070+
1071+
const kc = new KubeConfig();
1072+
kc.loadFromDefault();
1073+
1074+
expect(kc.clusters.length).to.equal(2);
1075+
expect(kc.users.length).to.equal(3);
1076+
expect(kc.contexts.length).to.equal(3);
1077+
expect(kc.getCurrentContext()).to.equal('context2');
1078+
});
10671079
});
10681080

10691081
function platformPath(path: string) {

0 commit comments

Comments
 (0)