1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Roman 2020-08-07 13:25:34 +03:00 committed by Lauri Nevala
parent 2287332f8b
commit 2894f31adb
6 changed files with 21 additions and 15 deletions

View File

@ -3,6 +3,12 @@ import { ClusterId, clusterStore } from "./cluster-store";
import { tracker } from "./tracker"; import { tracker } from "./tracker";
export const clusterIpc = { export const clusterIpc = {
init: createIpcChannel({
channel: "cluster:init",
handle: async (clusterId: ClusterId) => {
return clusterStore.getById(clusterId)?.pushState();
},
}),
activate: createIpcChannel({ activate: createIpcChannel({
channel: "cluster:activate", channel: "cluster:activate",
handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => { handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => {

View File

@ -64,7 +64,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
if (ipcRenderer) { if (ipcRenderer) {
ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => { ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => {
this.applyWithoutSync(() => { 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); const cluster = this.getById(clusterState.id);
if (cluster) cluster.updateModel(clusterState) if (cluster) cluster.updateModel(clusterState)
}) })

View File

@ -42,7 +42,7 @@ export class ClusterManager {
} }
getClusterForRequest(req: http.IncomingMessage): Cluster { 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] const clusterId = req.headers.host.split(".")[0]
return this.getCluster(clusterId) return this.getCluster(clusterId)
} }

View File

@ -2,7 +2,7 @@ import type { ClusterId, ClusterModel, ClusterPreferences } from "../common/clus
import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api"; import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
import type { WorkspaceId } from "../common/workspace-store"; import type { WorkspaceId } from "../common/workspace-store";
import type { FeatureStatusMap } from "./feature" 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 { apiKubePrefix } from "../common/vars";
import { broadcastIpc } from "../common/ipc"; import { broadcastIpc } from "../common/ipc";
import { ContextHandler } from "./context-handler" import { ContextHandler } from "./context-handler"
@ -217,6 +217,7 @@ export class Cluster implements ClusterModel {
return request(apiUrl, { return request(apiUrl, {
json: true, json: true,
timeout: 5000, timeout: 5000,
...options,
headers: { headers: {
Host: `${this.id}.${new URL(this.kubeProxyUrl).host}`, // required in ClusterManager.getClusterForRequest() Host: `${this.id}.${new URL(this.kubeProxyUrl).host}`, // required in ClusterManager.getClusterForRequest()
...(options.headers || {}), ...(options.headers || {}),
@ -228,6 +229,7 @@ export class Cluster implements ClusterModel {
const prometheusPrefix = this.preferences.prometheus?.prefix || ""; const prometheusPrefix = this.preferences.prometheus?.prefix || "";
const metricsPath = `/api/v1/namespaces/${prometheusPath}/proxy${prometheusPrefix}/api/v1/query_range`; const metricsPath = `/api/v1/namespaces/${prometheusPath}/proxy${prometheusPrefix}/api/v1/query_range`;
return this.k8sRequest(metricsPath, { return this.k8sRequest(metricsPath, {
timeout: 0,
resolveWithFullResponse: false, resolveWithFullResponse: false,
json: true, json: true,
qs: queryParams, qs: queryParams,

View File

@ -44,21 +44,21 @@ export class ClusterStatus extends React.Component<Props> {
error: res.error, error: res.error,
}); });
}) })
// await this.refreshClusterState(); await this.refreshCluster();
} }
componentWillUnmount() { componentWillUnmount() {
ipcRenderer.removeAllListeners(`kube-auth:${this.clusterId}`); ipcRenderer.removeAllListeners(`kube-auth:${this.clusterId}`);
} }
async refreshClusterState() { refreshCluster = async () => {
await clusterIpc.activate.invokeFromRenderer(this.clusterId); await clusterIpc.activate.invokeFromRenderer(this.clusterId);
} }
reconnect = async () => { reconnect = async () => {
this.authOutput = [{ data: "Reconnecting..." }]; this.authOutput = [{ data: "Reconnecting..." }];
this.isReconnecting = true; this.isReconnecting = true;
await this.refreshClusterState(); await this.refreshCluster();
this.isReconnecting = false; this.isReconnecting = false;
} }

View File

@ -7,6 +7,7 @@ import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { getMatchedClusterId } from "./cluster-view.route"; import { getMatchedClusterId } from "./cluster-view.route";
import { ClusterStatus } from "./cluster-status"; import { ClusterStatus } from "./cluster-status";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
import { clusterIpc } from "../../../common/cluster-ipc";
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component {
@ -24,7 +25,7 @@ export class ClusterView extends React.Component {
autorun(() => { autorun(() => {
if (this.cluster) { if (this.cluster) {
this.initView(this.cluster.id) 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("src", `//${clusterId}.${location.host}`)
webview.setAttribute("nodeintegration", "true") webview.setAttribute("nodeintegration", "true")
webview.setAttribute("enableremotemodule", "true") webview.setAttribute("enableremotemodule", "true")
// webview.addEventListener("did-start-loading", () => {
// webview.openDevTools();
// });
webview.addEventListener("did-finish-load", () => { webview.addEventListener("did-finish-load", () => {
// webview.openDevTools()
webview.classList.add("loaded"); 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) => { webview.addEventListener("did-fail-load", (event) => {
logger.error("failed to load lens-webview", event) logger.error("failed to load lens-webview", event)
@ -53,12 +53,10 @@ export class ClusterView extends React.Component {
ClusterView.views.set(clusterId, webview); ClusterView.views.set(clusterId, webview);
} }
activateView = async (clusterId: ClusterId) => { attachView = async (clusterId: ClusterId) => {
const cluster = clusterStore.getById(clusterId);
const view = ClusterView.views.get(clusterId); const view = ClusterView.views.get(clusterId);
const isLoaded = ClusterView.isLoaded.has(clusterId); const isLoaded = ClusterView.views.has(clusterId);
if (view && isLoaded && this.placeholder) { if (view && isLoaded && this.placeholder) {
cluster.pushState(); // fixme
this.placeholder.replaceWith(view); this.placeholder.replaceWith(view);
} }
} }