From 2894f31adb3f80dc7adb3300f2de2cf7ffd888db Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 7 Aug 2020 13:25:34 +0300 Subject: [PATCH] fixes Signed-off-by: Roman Signed-off-by: Lauri Nevala --- src/common/cluster-ipc.ts | 6 ++++++ src/common/cluster-store.ts | 2 +- src/main/cluster-manager.ts | 2 +- src/main/cluster.ts | 4 +++- .../cluster-manager/cluster-status.tsx | 6 +++--- .../components/cluster-manager/cluster-view.tsx | 16 +++++++--------- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/common/cluster-ipc.ts b/src/common/cluster-ipc.ts index 5d5dfe206d..6cc9219805 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/cluster-ipc.ts @@ -3,6 +3,12 @@ import { ClusterId, clusterStore } from "./cluster-store"; import { tracker } from "./tracker"; export const clusterIpc = { + init: createIpcChannel({ + channel: "cluster:init", + handle: async (clusterId: ClusterId) => { + return clusterStore.getById(clusterId)?.pushState(); + }, + }), activate: createIpcChannel({ channel: "cluster:activate", handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => { diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 90e27a4385..e4987d85a1 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -64,7 +64,7 @@ export class ClusterStore extends BaseStore { if (ipcRenderer) { ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => { this.applyWithoutSync(() => { - logger.info(`[CLUSTER-STORE]: received state update for cluster=${clusterState.id}`, clusterState); + logger.debug(`[CLUSTER-STORE]: received state update for cluster=${clusterState.id}`, clusterState); const cluster = this.getById(clusterState.id); if (cluster) cluster.updateModel(clusterState) }) diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 9eaebc9034..c18ee3c556 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -42,7 +42,7 @@ export class ClusterManager { } getClusterForRequest(req: http.IncomingMessage): Cluster { - logger.info(`getClusterForRequest(): ${req.headers.host}${req.url}`) + logger.debug(`getClusterForRequest(): ${req.headers.host}${req.url}`) const clusterId = req.headers.host.split(".")[0] return this.getCluster(clusterId) } diff --git a/src/main/cluster.ts b/src/main/cluster.ts index c6528c702f..a6b8975e3e 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -2,7 +2,7 @@ import type { ClusterId, ClusterModel, ClusterPreferences } from "../common/clus import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api"; import type { WorkspaceId } from "../common/workspace-store"; import type { FeatureStatusMap } from "./feature" -import { action, computed, observable, reaction, toJS, when } from "mobx"; +import { action, observable, reaction, toJS, when } from "mobx"; import { apiKubePrefix } from "../common/vars"; import { broadcastIpc } from "../common/ipc"; import { ContextHandler } from "./context-handler" @@ -217,6 +217,7 @@ export class Cluster implements ClusterModel { return request(apiUrl, { json: true, timeout: 5000, + ...options, headers: { Host: `${this.id}.${new URL(this.kubeProxyUrl).host}`, // required in ClusterManager.getClusterForRequest() ...(options.headers || {}), @@ -228,6 +229,7 @@ export class Cluster implements ClusterModel { const prometheusPrefix = this.preferences.prometheus?.prefix || ""; const metricsPath = `/api/v1/namespaces/${prometheusPath}/proxy${prometheusPrefix}/api/v1/query_range`; return this.k8sRequest(metricsPath, { + timeout: 0, resolveWithFullResponse: false, json: true, qs: queryParams, diff --git a/src/renderer/components/cluster-manager/cluster-status.tsx b/src/renderer/components/cluster-manager/cluster-status.tsx index 93fb2ada91..9a6849c20b 100644 --- a/src/renderer/components/cluster-manager/cluster-status.tsx +++ b/src/renderer/components/cluster-manager/cluster-status.tsx @@ -44,21 +44,21 @@ export class ClusterStatus extends React.Component { error: res.error, }); }) - // await this.refreshClusterState(); + await this.refreshCluster(); } componentWillUnmount() { ipcRenderer.removeAllListeners(`kube-auth:${this.clusterId}`); } - async refreshClusterState() { + refreshCluster = async () => { await clusterIpc.activate.invokeFromRenderer(this.clusterId); } reconnect = async () => { this.authOutput = [{ data: "Reconnecting..." }]; this.isReconnecting = true; - await this.refreshClusterState(); + await this.refreshCluster(); this.isReconnecting = false; } diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index ba6469cdee..bc815bd864 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -7,6 +7,7 @@ import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { getMatchedClusterId } from "./cluster-view.route"; import { ClusterStatus } from "./cluster-status"; import logger from "../../../main/logger"; +import { clusterIpc } from "../../../common/cluster-ipc"; @observer export class ClusterView extends React.Component { @@ -24,7 +25,7 @@ export class ClusterView extends React.Component { autorun(() => { if (this.cluster) { this.initView(this.cluster.id) - this.activateView(this.cluster.id) + this.attachView(this.cluster.id) } }) ]) @@ -39,12 +40,11 @@ export class ClusterView extends React.Component { webview.setAttribute("src", `//${clusterId}.${location.host}`) webview.setAttribute("nodeintegration", "true") webview.setAttribute("enableremotemodule", "true") - // webview.addEventListener("did-start-loading", () => { - // webview.openDevTools(); - // }); webview.addEventListener("did-finish-load", () => { + // webview.openDevTools() webview.classList.add("loaded"); - ClusterView.isLoaded.set(clusterId, true) + clusterIpc.init.invokeFromRenderer(clusterId); // push-state to webview + ClusterView.isLoaded.set(clusterId, true); }); webview.addEventListener("did-fail-load", (event) => { logger.error("failed to load lens-webview", event) @@ -53,12 +53,10 @@ export class ClusterView extends React.Component { ClusterView.views.set(clusterId, webview); } - activateView = async (clusterId: ClusterId) => { - const cluster = clusterStore.getById(clusterId); + attachView = async (clusterId: ClusterId) => { const view = ClusterView.views.get(clusterId); - const isLoaded = ClusterView.isLoaded.has(clusterId); + const isLoaded = ClusterView.views.has(clusterId); if (view && isLoaded && this.placeholder) { - cluster.pushState(); // fixme this.placeholder.replaceWith(view); } }