From 9004445d4f0524ad6d8b57782a9d8ef7fbbea85d Mon Sep 17 00:00:00 2001 From: Wekoslav Stefanovski Date: Tue, 6 Apr 2021 17:20:57 +0200 Subject: [PATCH] Added filtering of empty paths in KUBECONFIG --- src/config.ts | 2 +- src/config_test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 3abdff7098..d99ada4ef3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -284,7 +284,7 @@ export class KubeConfig { public loadFromDefault(opts?: Partial, contextFromStartingConfig: boolean = false): void { if (process.env.KUBECONFIG && process.env.KUBECONFIG.length > 0) { - const files = process.env.KUBECONFIG.split(path.delimiter); + const files = process.env.KUBECONFIG.split(path.delimiter).filter((filename: string) => filename); this.loadFromFile(files[0], opts); for (let i = 1; i < files.length; i++) { const kc = new KubeConfig(); diff --git a/src/config_test.ts b/src/config_test.ts index 0a0d79057b..144f02dcdb 100644 --- a/src/config_test.ts +++ b/src/config_test.ts @@ -1064,6 +1064,18 @@ describe('KubeConfig', () => { const kc = new KubeConfig(); expect(() => kc.loadFromDefault()).to.throw('Duplicate user: user1'); }); + + it('should ignore extra path delimiters', () => { + process.env.KUBECONFIG = path.delimiter + kcFileName + path.delimiter; + + const kc = new KubeConfig(); + kc.loadFromDefault(); + + expect(kc.clusters.length).to.equal(2); + expect(kc.users.length).to.equal(3); + expect(kc.contexts.length).to.equal(3); + expect(kc.getCurrentContext()).to.equal('context2'); + }); }); function platformPath(path: string) {