Skip to content

Commit

Permalink
Cannot login if my kube config doesn't exist #3872
Browse files Browse the repository at this point in the history
Creates a minimalistic Kube config file in `~/.kube/` directory needed for
`@kubernetes/client-node` API.
The file contents doesn't define any clusters/users/contexts/etc. properties.

Fixes: #3872

Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny authored and datho7561 committed Nov 29, 2024
1 parent 25931b6 commit 938dd6f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/util/kubeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,17 @@ export function getKubeConfigFiles(): string[] {
}
return filesThatExist;
}
return [path.join(Platform.getUserHomePath(), '.kube', 'config')];

const defaultKubeConfigFile = path.join(Platform.getUserHomePath(), '.kube', 'config');
if (!fs.existsSync(defaultKubeConfigFile)) {
try {
fs.appendFileSync(defaultKubeConfigFile, 'apiVersion: v1'); // Create Kube Config with minimal content
} catch (err) {
void window.showErrorMessage(`Kubernetes configuration file cannot be created at '${defaultKubeConfigFile}': ${err}`);
}
}

return [defaultKubeConfigFile];
}

/**
Expand Down

0 comments on commit 938dd6f

Please sign in to comment.