Skip to content

Commit

Permalink
Merge pull request #628 from sweko/master
Browse files Browse the repository at this point in the history
Added filtering of empty paths in KUBECONFIG
  • Loading branch information
k8s-ci-robot authored Apr 7, 2021
2 parents 7f3bbfd + 9004445 commit 5dd9180
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class KubeConfig {

public loadFromDefault(opts?: Partial<ConfigOptions>, 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();
Expand Down
12 changes: 12 additions & 0 deletions src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5dd9180

Please sign in to comment.