Fix: Recreate proxy kubeconfig if it is deleted (#2372)

This commit is contained in:
Lauri Nevala authored and GitHub committed 2021-03-23 08:12:01 -04:00
1 parent e70ac87c52
commit 4afec72ceb
11 files changed
+72 -43

No files matched your search

+14 -5
View File
@@ -24,14 +24,24 @@ export class KubeconfigManager {
protected async init() {
try {
await this.contextHandler.ensurePort();
await this.createProxyKubeconfig();
this.tempFile = await this.createProxyKubeconfig();
} catch (err) {
logger.error(`Failed to created temp config for auth-proxy`, { err });
}
}
getPath() {
async getPath() {
// create proxy kubeconfig if it is removed
if (this.tempFile !== undefined && !(await fs.pathExists(this.tempFile))) {
try {
this.tempFile = await this.createProxyKubeconfig();
} catch (err) {
logger.error(`Failed to created temp config for auth-proxy`, { err });
}
}
return this.tempFile;
}
protected resolveProxyUrl() {
@@ -71,9 +81,8 @@ export class KubeconfigManager {
// write
const configYaml = dumpConfigYaml(proxyConfig);
fs.ensureDir(path.dirname(tempFile));
fs.writeFileSync(tempFile, configYaml, { mode: 0o600 });
this.tempFile = tempFile;
await fs.ensureDir(path.dirname(tempFile));
await fs.writeFile(tempFile, configYaml, { mode: 0o600 });
logger.debug(`Created temp kubeconfig "${contextName}" at "${tempFile}": \n${configYaml}`);
return tempFile;