From 790800346747ba05fab64aa8e100e96a1dc7350c Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 5 Nov 2021 14:49:00 -0400 Subject: [PATCH] Broadcast cluster's disconnected state before stopping KubeAuthProxy Signed-off-by: Sebastian Malton --- integration/__tests__/cluster-pages.tests.ts | 3 +++ integration/helpers/utils.ts | 15 ++++++++------- src/common/cluster/cluster.ts | 8 ++++++-- src/main/__test__/cluster.test.ts | 19 +++++++++++++++++++ .../__test__/kubeconfig-sync.test.ts | 1 + src/main/kube-auth-proxy/kube-auth-proxy.ts | 2 +- .../components/cluster-manager/lens-views.ts | 2 ++ 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/integration/__tests__/cluster-pages.tests.ts b/integration/__tests__/cluster-pages.tests.ts index 6dc89020e3..d20af1d6eb 100644 --- a/integration/__tests__/cluster-pages.tests.ts +++ b/integration/__tests__/cluster-pages.tests.ts @@ -312,6 +312,8 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => { }, 10*60*1000); afterEach(async () => { + await frame.click(`[data-testid="sidebar-cluster-dropdown"]`); + await frame.click(`.Menu >> text="Disconnect"`); await cleanup(); }, 10*60*1000); @@ -321,6 +323,7 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => { await frame.waitForSelector(`.Menu >> text="Settings"`); await frame.waitForSelector(`.Menu >> text="Disconnect"`); await frame.waitForSelector(`.Menu >> text="Delete"`); + await frame.click(`[data-testid="sidebar-cluster-dropdown"]`); }); it("should navigate around common cluster pages", async () => { diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index e79ff1ca72..b2a4f2ed4f 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -56,7 +56,12 @@ export async function start() { ...process.env, }, timeout: 100_000, - } as Parameters[0]); + }); + + const cleanup = async () => { + await app.close(); + await remove(CICD).catch(noop); + }; try { const window = await getMainWindow(app); @@ -64,14 +69,10 @@ export async function start() { return { app, window, - cleanup: async () => { - await app.close(); - await remove(CICD).catch(noop); - }, + cleanup, }; } catch (error) { - await app.close(); - await remove(CICD).catch(noop); + await cleanup(); throw error; } } diff --git a/src/common/cluster/cluster.ts b/src/common/cluster/cluster.ts index 911c2dd8fa..fcb790243e 100644 --- a/src/common/cluster/cluster.ts +++ b/src/common/cluster/cluster.ts @@ -375,9 +375,13 @@ export class Cluster implements ClusterModel, ClusterState { * @internal */ @action disconnect() { - logger.info(`[CLUSTER]: disconnecting`, { id: this.id }); + logger.info(`[CLUSTER]: disconnecting cluster`, { id: this.id }); + + ipcMain.once(`cluster:${this.id}:frame-removed`, () => { + this.contextHandler?.stopServer(); + }); + this.eventsDisposer(); - this.contextHandler?.stopServer(); this.disconnected = true; this.online = false; this.accessible = false; diff --git a/src/main/__test__/cluster.test.ts b/src/main/__test__/cluster.test.ts index d528f9f9ac..5e90a767cf 100644 --- a/src/main/__test__/cluster.test.ts +++ b/src/main/__test__/cluster.test.ts @@ -20,6 +20,8 @@ jest.mock("winston", () => ({ label: jest.fn(), timestamp: jest.fn(), printf: jest.fn(), + padLevels: jest.fn(), + ms: jest.fn(), }, createLogger: jest.fn().mockReturnValue(logger), transports: { @@ -32,6 +34,23 @@ jest.mock("../../common/ipc"); jest.mock("request"); jest.mock("request-promise-native"); +jest.mock("electron", () => ({ + app: { + getVersion: () => "99.99.99", + getName: () => "lens", + setName: jest.fn(), + setPath: jest.fn(), + getPath: () => "tmp", + getLocale: () => "en", + setLoginItemSettings: jest.fn(), + }, + ipcMain: { + on: jest.fn(), + once: jest.fn(), + handle: jest.fn(), + }, +})); + import { Console } from "console"; import mockFs from "mock-fs"; import type { Cluster } from "../../common/cluster/cluster"; diff --git a/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts b/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts index f04458c3c8..3ba9986cfa 100644 --- a/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts +++ b/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts @@ -30,6 +30,7 @@ jest.mock("electron", () => ({ }, ipcMain: { on: jest.fn(), + once: jest.fn(), handle: jest.fn(), }, })); diff --git a/src/main/kube-auth-proxy/kube-auth-proxy.ts b/src/main/kube-auth-proxy/kube-auth-proxy.ts index 1e96d69980..dffc77cc12 100644 --- a/src/main/kube-auth-proxy/kube-auth-proxy.ts +++ b/src/main/kube-auth-proxy/kube-auth-proxy.ts @@ -107,7 +107,7 @@ export class KubeAuthProxy { this.ready = false; if (this.proxyProcess) { - logger.debug("[KUBE-AUTH]: stopping local proxy", this.cluster.getMeta()); + logger.info("[KUBE-AUTH]: stopping local proxy", { clusterId: this.cluster.id }); this.proxyProcess.removeAllListeners(); this.proxyProcess.stderr.removeAllListeners(); this.proxyProcess.stdout.removeAllListeners(); diff --git a/src/renderer/components/cluster-manager/lens-views.ts b/src/renderer/components/cluster-manager/lens-views.ts index edd3b6d0c7..787c2bbf15 100644 --- a/src/renderer/components/cluster-manager/lens-views.ts +++ b/src/renderer/components/cluster-manager/lens-views.ts @@ -5,6 +5,7 @@ import { action, IReactionDisposer, makeObservable, observable, when } from "mobx"; import logger from "../../../main/logger"; +import { broadcastMessage } from "../../../common/ipc"; import { clusterVisibilityHandler } from "../../../common/cluster-ipc"; import { ClusterStore } from "../../../common/cluster-store/cluster-store"; import type { ClusterId } from "../../../common/cluster-types"; @@ -72,6 +73,7 @@ export class ClusterFrameHandler extends Singleton { logger.info(`[LENS-VIEW]: remove dashboard, clusterId=${clusterId}`); this.views.delete(clusterId); iframe.parentNode.removeChild(iframe); + broadcastMessage(`cluster:${clusterId}:frame-removed`); dispose(); }, );