mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Modify cluster.disconnected in a seperate action
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4ac53a5481
commit
6fbf4bff06
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import { action, comparer, computed, makeObservable, observable, reaction, when } from "mobx";
|
import { action, comparer, computed, makeObservable, observable, reaction, runInAction, when } from "mobx";
|
||||||
import { broadcastMessage } from "../ipc";
|
import { broadcastMessage } from "../ipc";
|
||||||
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
||||||
import { HttpError, KubeConfig } from "@kubernetes/client-node";
|
import { HttpError, KubeConfig } from "@kubernetes/client-node";
|
||||||
@ -287,7 +287,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected bindEvents() {
|
protected bindEvents() {
|
||||||
logger.info(`[CLUSTER]: bind events`, this.getMeta());
|
logger.info(`[CLUSTER]: bind events`, this.getMeta(true));
|
||||||
const refreshTimer = setInterval(() => !this.disconnected && this.refresh(), 30000); // every 30s
|
const refreshTimer = setInterval(() => !this.disconnected && this.refresh(), 30000); // every 30s
|
||||||
const refreshMetadataTimer = setInterval(() => !this.disconnected && this.refreshMetadata(), 900000); // every 15 minutes
|
const refreshMetadataTimer = setInterval(() => !this.disconnected && this.refreshMetadata(), 900000); // every 15 minutes
|
||||||
|
|
||||||
@ -324,34 +324,38 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
async activate(force = false) {
|
async activate(force = false) {
|
||||||
if (this.activated && !force) {
|
try {
|
||||||
return this.pushState();
|
logger.info(`[CLUSTER]: activating`, this.getMeta(true));
|
||||||
|
|
||||||
|
if (this.activated && !force) {
|
||||||
|
return this.pushState();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.eventsDisposer.length) {
|
||||||
|
this.bindEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.disconnected || !this.accessible) {
|
||||||
|
await this.reconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.broadcastConnectUpdate("Refreshing connection status ...");
|
||||||
|
await this.refreshConnectionStatus();
|
||||||
|
|
||||||
|
if (this.accessible) {
|
||||||
|
this.broadcastConnectUpdate("Refreshing cluster accessibility ...");
|
||||||
|
await this.refreshAccessibility();
|
||||||
|
// download kubectl in background, so it's not blocking dashboard
|
||||||
|
this.ensureKubectl()
|
||||||
|
.catch(error => logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error));
|
||||||
|
this.broadcastConnectUpdate("Connected, waiting for view to load ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.activated = true;
|
||||||
|
this.pushState();
|
||||||
|
} finally {
|
||||||
|
logger.info(`[CLUSTER]: activation finished`, this.getMeta());
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`[CLUSTER]: activate`, this.getMeta());
|
|
||||||
|
|
||||||
if (!this.eventsDisposer.length) {
|
|
||||||
this.bindEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.disconnected || !this.accessible) {
|
|
||||||
await this.reconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.broadcastConnectUpdate("Refreshing connection status ...");
|
|
||||||
await this.refreshConnectionStatus();
|
|
||||||
|
|
||||||
if (this.accessible) {
|
|
||||||
this.broadcastConnectUpdate("Refreshing cluster accessibility ...");
|
|
||||||
await this.refreshAccessibility();
|
|
||||||
// download kubectl in background, so it's not blocking dashboard
|
|
||||||
this.ensureKubectl()
|
|
||||||
.catch(error => logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error));
|
|
||||||
this.broadcastConnectUpdate("Connected, waiting for view to load ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.activated = true;
|
|
||||||
this.pushState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -368,19 +372,18 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@action
|
|
||||||
async reconnect() {
|
async reconnect() {
|
||||||
logger.info(`[CLUSTER]: reconnect`, this.getMeta());
|
runInAction(() => this.disconnected = false);
|
||||||
this.contextHandler?.stopServer();
|
this.contextHandler?.stopServer();
|
||||||
|
logger.info(`[CLUSTER]: starting proxy server`, this.getMeta(true));
|
||||||
await this.contextHandler?.ensureServer();
|
await this.contextHandler?.ensureServer();
|
||||||
this.disconnected = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@action disconnect() {
|
@action disconnect() {
|
||||||
logger.info(`[CLUSTER]: disconnecting`, { id: this.id });
|
logger.info(`[CLUSTER]: disconnecting`, this.getMeta(true));
|
||||||
this.eventsDisposer();
|
this.eventsDisposer();
|
||||||
this.contextHandler?.stopServer();
|
this.contextHandler?.stopServer();
|
||||||
this.disconnected = true;
|
this.disconnected = true;
|
||||||
@ -391,7 +394,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
this.allowedNamespaces = [];
|
this.allowedNamespaces = [];
|
||||||
this.resourceAccessStatuses.clear();
|
this.resourceAccessStatuses.clear();
|
||||||
this.pushState();
|
this.pushState();
|
||||||
logger.info(`[CLUSTER]: disconnected`, { id: this.id });
|
logger.info(`[CLUSTER]: disconnected`, this.getMeta(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -400,7 +403,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
async refresh(opts: ClusterRefreshOptions = {}) {
|
async refresh(opts: ClusterRefreshOptions = {}) {
|
||||||
logger.info(`[CLUSTER]: refresh`, this.getMeta());
|
logger.info(`[CLUSTER]: refresh`, this.getMeta(true));
|
||||||
await this.refreshConnectionStatus();
|
await this.refreshConnectionStatus();
|
||||||
|
|
||||||
if (this.accessible) {
|
if (this.accessible) {
|
||||||
@ -570,15 +573,23 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get cluster system meta, e.g. use in "logger"
|
// get cluster system meta, e.g. use in "logger"
|
||||||
getMeta() {
|
getMeta(basic = false) {
|
||||||
return {
|
const meta = {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
name: this.contextName,
|
name: this.contextName,
|
||||||
ready: this.ready,
|
kubeconfigPath: this.kubeConfigPath,
|
||||||
online: this.online,
|
|
||||||
accessible: this.accessible,
|
|
||||||
disconnected: this.disconnected,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!basic) {
|
||||||
|
Object.assign(meta, {
|
||||||
|
ready: this.ready,
|
||||||
|
online: this.online,
|
||||||
|
accessible: this.accessible,
|
||||||
|
disconnected: this.disconnected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user