Skip to content

Commit 2aa448f

Browse files
authored
Merge pull request #652 from TattdCodeMonkey/wsl-kubeconfig-env
Loading KubeConfig from wsl
2 parents e632ad8 + 0396bf5 commit 2aa448f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/config.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,24 @@ export class KubeConfig {
302302
}
303303
}
304304
if (process.platform === 'win32' && shelljs.which('wsl.exe')) {
305-
// TODO: Handle if someome set $KUBECONFIG in wsl here...
306305
try {
307-
const result = execa.sync('wsl.exe', ['cat', shelljs.homedir() + '/.kube/config']);
306+
const envKubeconfigPathResult = execa.sync('wsl.exe', ['bash', '-ic', 'printenv KUBECONFIG']);
307+
if (envKubeconfigPathResult.exitCode === 0 && envKubeconfigPathResult.stdout.length > 0) {
308+
const result = execa.sync('wsl.exe', ['cat', envKubeconfigPathResult.stdout]);
309+
if (result.exitCode === 0) {
310+
this.loadFromString(result.stdout, opts);
311+
return;
312+
}
313+
if (result.exitCode === 0) {
314+
this.loadFromString(result.stdout, opts);
315+
return;
316+
}
317+
}
318+
} catch (err) {
319+
// Falling back to default kubeconfig
320+
}
321+
try {
322+
const result = execa.sync('wsl.exe', ['cat', '~/.kube/config']);
308323
if (result.exitCode === 0) {
309324
this.loadFromString(result.stdout, opts);
310325
return;

0 commit comments

Comments
 (0)