Skip to content

Commit 0396bf5

Browse files
check for $KUBECONFIG in wsl
Loaded KUBECONFIG from wsl env if available. To check for KUBECONFIG env variable I had to run bash in interactive mode instead of just running `wsl.exe echo` since that would not find a user's environment variables. using printenv KUBECONFIG did work as expected using wsl2 and Ubuntu 20.04
1 parent 3530129 commit 0396bf5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,22 @@ export class KubeConfig {
302302
}
303303
}
304304
if (process.platform === 'win32' && shelljs.which('wsl.exe')) {
305-
// TODO: Handle if someome set $KUBECONFIG in wsl here...
305+
try {
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+
}
306321
try {
307322
const result = execa.sync('wsl.exe', ['cat', '~/.kube/config']);
308323
if (result.exitCode === 0) {

0 commit comments

Comments
 (0)