mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Re-create proxy kubeconfig if it's removed from the filesystem
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
b066fb3527
commit
41d139b266
@ -24,14 +24,20 @@ export class KubeconfigManager {
|
|||||||
protected async init() {
|
protected async init() {
|
||||||
try {
|
try {
|
||||||
await this.contextHandler.ensurePort();
|
await this.contextHandler.ensurePort();
|
||||||
await this.createProxyKubeconfig();
|
this.tempFile = this.createProxyKubeconfig();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Failed to created temp config for auth-proxy`, { err });
|
logger.error(`Failed to created temp config for auth-proxy`, { err });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPath() {
|
getPath() {
|
||||||
|
// create proxy kubeconfig if it is removed
|
||||||
|
if (!this.tempFile || !fs.pathExistsSync(this.tempFile)) {
|
||||||
|
this.tempFile = this.createProxyKubeconfig();
|
||||||
|
}
|
||||||
|
|
||||||
return this.tempFile;
|
return this.tempFile;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected resolveProxyUrl() {
|
protected resolveProxyUrl() {
|
||||||
@ -42,7 +48,7 @@ export class KubeconfigManager {
|
|||||||
* Creates new "temporary" kubeconfig that point to the kubectl-proxy.
|
* Creates new "temporary" kubeconfig that point to the kubectl-proxy.
|
||||||
* This way any user of the config does not need to know anything about the auth etc. details.
|
* This way any user of the config does not need to know anything about the auth etc. details.
|
||||||
*/
|
*/
|
||||||
protected async createProxyKubeconfig(): Promise<string> {
|
protected createProxyKubeconfig(): string {
|
||||||
const { configDir, cluster } = this;
|
const { configDir, cluster } = this;
|
||||||
const { contextName, kubeConfigPath, id } = cluster;
|
const { contextName, kubeConfigPath, id } = cluster;
|
||||||
const tempFile = path.join(configDir, `kubeconfig-${id}`);
|
const tempFile = path.join(configDir, `kubeconfig-${id}`);
|
||||||
@ -73,7 +79,6 @@ export class KubeconfigManager {
|
|||||||
|
|
||||||
fs.ensureDir(path.dirname(tempFile));
|
fs.ensureDir(path.dirname(tempFile));
|
||||||
fs.writeFileSync(tempFile, configYaml, { mode: 0o600 });
|
fs.writeFileSync(tempFile, configYaml, { mode: 0o600 });
|
||||||
this.tempFile = tempFile;
|
|
||||||
logger.debug(`Created temp kubeconfig "${contextName}" at "${tempFile}": \n${configYaml}`);
|
logger.debug(`Created temp kubeconfig "${contextName}" at "${tempFile}": \n${configYaml}`);
|
||||||
|
|
||||||
return tempFile;
|
return tempFile;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user