mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto-refresh status only for active (selected) cluster
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
e7fc6b4a35
commit
aab91863fc
7 files changed
+37
-26
No files matched your search
@@ -39,6 +39,13 @@ export class ClusterManager {
|
||||
removedClusters.clear();
|
||||
}
|
||||
});
|
||||
// auto-refresh status for active cluster
|
||||
autorun(() => {
|
||||
const { activeCluster } = clusterStore;
|
||||
if (activeCluster && activeCluster.initialized) {
|
||||
activeCluster.refreshStatus();
|
||||
}
|
||||
});
|
||||
// listen ipc-events
|
||||
ClusterManager.ipcListen(this);
|
||||
}
|
||||
@@ -87,7 +94,6 @@ export class ClusterManager {
|
||||
}
|
||||
}
|
||||
|
||||
// fixme
|
||||
getClusterForRequest(req: http.IncomingMessage): Cluster {
|
||||
let cluster: Cluster = null
|
||||
|
||||
@@ -147,7 +153,10 @@ export class ClusterManager {
|
||||
}
|
||||
|
||||
protected async refreshCluster(clusterId: ClusterId) {
|
||||
await this.getCluster(clusterId)?.refreshStatus();
|
||||
const cluster = this.getCluster(clusterId);
|
||||
if (cluster) {
|
||||
await cluster.refreshStatus();
|
||||
}
|
||||
}
|
||||
|
||||
static ipcListen(clusterManager: ClusterManager) {
|
||||
|
||||
+7
-13
@@ -42,7 +42,6 @@ export class Cluster implements ClusterModel {
|
||||
@observable kubeConfigPath: string;
|
||||
@observable url: string; // cluster-api url
|
||||
@observable proxyUrl: string; // lens-proxy url
|
||||
@observable kubeProxyUrl: string;
|
||||
@observable webContentUrl: string;
|
||||
@observable proxyPort: number;
|
||||
@observable online: boolean;
|
||||
@@ -60,32 +59,26 @@ export class Cluster implements ClusterModel {
|
||||
this.updateModel(model);
|
||||
}
|
||||
|
||||
@action
|
||||
updateModel(model: ClusterModel) {
|
||||
Object.assign(this, model);
|
||||
if (!this.contextName) {
|
||||
this.contextName = this.preferences.clusterName;
|
||||
}
|
||||
this.url = this.getKubeconfig().getCurrentCluster().server;
|
||||
this.contextName = this.preferences.clusterName;
|
||||
}
|
||||
|
||||
@action
|
||||
async init(proxyPort: number) {
|
||||
try {
|
||||
this.proxyPort = proxyPort;
|
||||
this.url = this.getKubeconfig().getCurrentCluster().server;
|
||||
this.proxyUrl = `http://localhost:${proxyPort}`;
|
||||
this.kubeProxyUrl = this.proxyUrl + apiKubePrefix;
|
||||
this.webContentUrl = `http://${this.id}.localhost:${proxyPort}`;
|
||||
|
||||
this.contextHandler = new ContextHandler(this);
|
||||
this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler);
|
||||
await this.refreshStatus();
|
||||
this.proxyUrl = `http://localhost:${proxyPort}`;
|
||||
this.webContentUrl = `http://${this.id}.localhost:${proxyPort}`;
|
||||
this.initialized = true;
|
||||
|
||||
logger.info(`[CLUSTER]: init success`, {
|
||||
id: this.id,
|
||||
url: this.url,
|
||||
proxyUrl: this.proxyUrl,
|
||||
kubeProxyUrl: this.kubeProxyUrl,
|
||||
webContentUrl: this.webContentUrl,
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -150,7 +143,8 @@ export class Cluster implements ClusterModel {
|
||||
}
|
||||
|
||||
protected k8sRequest(path: string, options: RequestPromiseOptions = {}) {
|
||||
return request(this.kubeProxyUrl + path, {
|
||||
const apiUrl = this.proxyUrl + apiKubePrefix + path;
|
||||
return request(apiUrl, {
|
||||
json: true,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
|
||||
@@ -80,7 +80,6 @@ export class ContextHandler {
|
||||
return apiTarget
|
||||
}
|
||||
|
||||
// fixme
|
||||
public async getApiTargetUrl(): Promise<string> {
|
||||
await this.ensurePort();
|
||||
return `http://127.0.0.1:${this.proxyPort}${this.clusterUrl.path}`;
|
||||
|
||||
Reference in new issue
Block a user