mirror of
https://github.com/lensapp/lens.git
synced 2024-09-21 14:27:46 +03:00
Optimise cluster activate and refresh (#938)
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
bddc6b33e3
commit
299eceaee4
@ -14,6 +14,14 @@ export const clusterIpc = {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
refresh: createIpcChannel({
|
||||||
|
channel: "cluster:refresh",
|
||||||
|
handle: (clusterId: ClusterId) => {
|
||||||
|
const cluster = clusterStore.getById(clusterId);
|
||||||
|
if (cluster) return cluster.refresh();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
disconnect: createIpcChannel({
|
disconnect: createIpcChannel({
|
||||||
channel: "cluster:disconnect",
|
channel: "cluster:disconnect",
|
||||||
handle: (clusterId: ClusterId) => {
|
handle: (clusterId: ClusterId) => {
|
||||||
|
@ -133,7 +133,13 @@ export class Cluster implements ClusterModel {
|
|||||||
if (this.disconnected || (!init && !this.accessible)) {
|
if (this.disconnected || (!init && !this.accessible)) {
|
||||||
await this.reconnect();
|
await this.reconnect();
|
||||||
}
|
}
|
||||||
await this.refresh();
|
await this.refreshConnectionStatus()
|
||||||
|
if (this.accessible) {
|
||||||
|
await this.refreshAllowedResources()
|
||||||
|
this.ready = true
|
||||||
|
this.kubeCtl = new Kubectl(this.version)
|
||||||
|
this.kubeCtl.ensureKubectl() // download kubectl in background, so it's not blocking dashboard
|
||||||
|
}
|
||||||
return this.pushState();
|
return this.pushState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,15 +165,14 @@ export class Cluster implements ClusterModel {
|
|||||||
@action
|
@action
|
||||||
async refresh() {
|
async refresh() {
|
||||||
logger.info(`[CLUSTER]: refresh`, this.getMeta());
|
logger.info(`[CLUSTER]: refresh`, this.getMeta());
|
||||||
await this.refreshConnectionStatus(); // refresh "version", "online", etc.
|
await this.whenInitialized;
|
||||||
|
await this.refreshConnectionStatus();
|
||||||
if (this.accessible) {
|
if (this.accessible) {
|
||||||
this.kubeCtl = new Kubectl(this.version)
|
|
||||||
this.distribution = this.detectKubernetesDistribution(this.version)
|
this.distribution = this.detectKubernetesDistribution(this.version)
|
||||||
const [features, isAdmin, nodesCount] = await Promise.all([
|
const [features, isAdmin, nodesCount] = await Promise.all([
|
||||||
getFeatures(this),
|
getFeatures(this),
|
||||||
this.isClusterAdmin(),
|
this.isClusterAdmin(),
|
||||||
this.getNodeCount(),
|
this.getNodeCount(),
|
||||||
this.kubeCtl.ensureKubectl()
|
|
||||||
]);
|
]);
|
||||||
this.features = features;
|
this.features = features;
|
||||||
this.isAdmin = isAdmin;
|
this.isAdmin = isAdmin;
|
||||||
@ -176,8 +181,8 @@ export class Cluster implements ClusterModel {
|
|||||||
this.refreshEvents(),
|
this.refreshEvents(),
|
||||||
this.refreshAllowedResources(),
|
this.refreshAllowedResources(),
|
||||||
]);
|
]);
|
||||||
this.ready = true
|
|
||||||
}
|
}
|
||||||
|
this.pushState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -39,7 +39,7 @@ export class ShellSession extends EventEmitter {
|
|||||||
public async open() {
|
public async open() {
|
||||||
this.kubectlBinDir = await this.kubectl.binDir()
|
this.kubectlBinDir = await this.kubectl.binDir()
|
||||||
const pathFromPreferences = userStore.preferences.kubectlBinariesPath || Kubectl.bundledKubectlPath
|
const pathFromPreferences = userStore.preferences.kubectlBinariesPath || Kubectl.bundledKubectlPath
|
||||||
this.kubectlPathDir = userStore.preferences.downloadKubectlBinaries ? await this.kubectl.binDir() : path.dirname(pathFromPreferences)
|
this.kubectlPathDir = userStore.preferences.downloadKubectlBinaries ? this.kubectlBinDir : path.dirname(pathFromPreferences)
|
||||||
this.helmBinDir = helmCli.getBinaryDir()
|
this.helmBinDir = helmCli.getBinaryDir()
|
||||||
const env = await this.getCachedShellEnv()
|
const env = await this.getCachedShellEnv()
|
||||||
const shell = env.PTYSHELL
|
const shell = env.PTYSHELL
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import "./cluster-settings.scss";
|
import "./cluster-settings.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { observer, disposeOnUnmount } from "mobx-react";
|
||||||
import { Features } from "./features";
|
import { Features } from "./features";
|
||||||
import { Removal } from "./removal";
|
import { Removal } from "./removal";
|
||||||
import { Status } from "./status";
|
import { Status } from "./status";
|
||||||
import { General } from "./general";
|
import { General } from "./general";
|
||||||
|
import { Cluster } from "../../../main/cluster";
|
||||||
import { WizardLayout } from "../layout/wizard-layout";
|
import { WizardLayout } from "../layout/wizard-layout";
|
||||||
import { ClusterIcon } from "../cluster-icon";
|
import { ClusterIcon } from "../cluster-icon";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
@ -13,14 +14,25 @@ import { navigate } from "../../navigation";
|
|||||||
import { IClusterSettingsRouteParams } from "./cluster-settings.route";
|
import { IClusterSettingsRouteParams } from "./cluster-settings.route";
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { RouteComponentProps } from "react-router";
|
import { RouteComponentProps } from "react-router";
|
||||||
|
import { clusterIpc } from "../../../common/cluster-ipc";
|
||||||
|
import { autorun } from "mobx";
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<IClusterSettingsRouteParams> {
|
interface Props extends RouteComponentProps<IClusterSettingsRouteParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterSettings extends React.Component<Props> {
|
export class ClusterSettings extends React.Component<Props> {
|
||||||
|
get cluster(): Cluster {
|
||||||
|
return clusterStore.getById(this.props.match.params.clusterId);
|
||||||
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
window.addEventListener('keydown', this.onEscapeKey);
|
window.addEventListener('keydown', this.onEscapeKey);
|
||||||
|
disposeOnUnmount(this,
|
||||||
|
autorun(() => {
|
||||||
|
this.refreshCluster();
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -34,12 +46,18 @@ export class ClusterSettings extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshCluster = () => {
|
||||||
|
if(this.cluster) {
|
||||||
|
clusterIpc.refresh.invokeFromRenderer(this.cluster.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
navigate("/");
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const cluster = clusterStore.getById(this.props.match.params.clusterId);
|
const cluster = this.cluster
|
||||||
if (!cluster) return null;
|
if (!cluster) return null;
|
||||||
const header = (
|
const header = (
|
||||||
<>
|
<>
|
||||||
|
@ -39,7 +39,7 @@ export class ClusterStatus extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
if (this.cluster.disconnected) {
|
if (this.cluster.disconnected) {
|
||||||
await this.refreshCluster();
|
await this.activateCluster();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,13 +47,13 @@ export class ClusterStatus extends React.Component<Props> {
|
|||||||
ipcRenderer.removeAllListeners(`kube-auth:${this.props.clusterId}`);
|
ipcRenderer.removeAllListeners(`kube-auth:${this.props.clusterId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshCluster = async () => {
|
activateCluster = async () => {
|
||||||
await clusterIpc.activate.invokeFromRenderer(this.props.clusterId);
|
await clusterIpc.activate.invokeFromRenderer(this.props.clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
reconnect = async () => {
|
reconnect = async () => {
|
||||||
this.isReconnecting = true;
|
this.isReconnecting = true;
|
||||||
await this.refreshCluster();
|
await this.activateCluster();
|
||||||
this.isReconnecting = false;
|
this.isReconnecting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user