1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-04-21 06:44:07 +03:00
parent 39bc756f11
commit 06893c3fbc
2 changed files with 11 additions and 5 deletions

View File

@ -109,6 +109,8 @@ describe("kubeconfig manager tests", () => {
await kubeConfManager.unlink(); await kubeConfManager.unlink();
expect(await fse.pathExists(configPath)).toBe(false); expect(await fse.pathExists(configPath)).toBe(false);
await kubeConfManager.unlink(); // doesn't throw await kubeConfManager.unlink(); // doesn't throw
expect(await kubeConfManager.getPath()).toBeUndefined(); expect(async () => {
await kubeConfManager.getPath();
}).rejects.toThrow("already unlinked");
}); });
}); });

View File

@ -13,13 +13,17 @@ export class KubeconfigManager {
constructor(protected cluster: Cluster, protected contextHandler: ContextHandler, protected port: number) { } constructor(protected cluster: Cluster, protected contextHandler: ContextHandler, protected port: number) { }
async getPath() { async getPath(): Promise<string> {
if (!this.tempFile && this.tempFile !== undefined) { if (this.tempFile === undefined) {
throw new Error("kubeconfig is already unlinked");
}
if (!this.tempFile) {
await this.init(); await this.init();
} }
// create proxy kubeconfig if it is removed // create proxy kubeconfig if it is removed without unlink called
if (this.tempFile !== undefined && !(await fs.pathExists(this.tempFile))) { if (!(await fs.pathExists(this.tempFile))) {
try { try {
this.tempFile = await this.createProxyKubeconfig(); this.tempFile = await this.createProxyKubeconfig();
} catch (err) { } catch (err) {