mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Improve how kubernetes cluster status is resolved (#2909)
This commit is contained in:
1 parent
0ad44d6f40
commit
39149eedfd
4 files changed
+36
-6
No files matched your search
@@ -48,6 +48,15 @@ export class CatalogEntityRegistry {
|
||||
return allItems.filter((entity) => this.categoryRegistry.getCategoryForEntity(entity) !== undefined);
|
||||
}
|
||||
|
||||
getById<T extends CatalogEntity>(id: string): T | undefined {
|
||||
const item = this.items.find((entity) => entity.metadata.uid === id);
|
||||
|
||||
if (item) return item as T;
|
||||
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||
const items = this.items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);
|
||||
|
||||
|
||||
@@ -79,8 +79,7 @@ export class ClusterManager extends Singleton {
|
||||
if (index !== -1) {
|
||||
const entity = catalogEntityRegistry.items[index] as KubernetesCluster;
|
||||
|
||||
entity.status.phase = cluster.disconnected ? "disconnected" : "connected";
|
||||
entity.status.active = !cluster.disconnected;
|
||||
this.updateEntityStatus(entity, cluster);
|
||||
|
||||
if (cluster.preferences?.clusterName) {
|
||||
entity.metadata.name = cluster.preferences.clusterName;
|
||||
@@ -101,6 +100,10 @@ export class ClusterManager extends Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
protected updateEntityStatus(entity: KubernetesCluster, cluster: Cluster) {
|
||||
entity.status.phase = cluster.accessible ? "connected" : "disconnected";
|
||||
}
|
||||
|
||||
@action syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
||||
for (const entity of entities) {
|
||||
const cluster = this.store.getById(entity.metadata.uid);
|
||||
@@ -118,10 +121,7 @@ export class ClusterManager extends Singleton {
|
||||
cluster.kubeConfigPath = entity.spec.kubeconfigPath;
|
||||
cluster.contextName = entity.spec.kubeconfigContext;
|
||||
|
||||
entity.status = {
|
||||
phase: cluster.disconnected ? "disconnected" : "connected",
|
||||
active: !cluster.disconnected
|
||||
};
|
||||
this.updateEntityStatus(entity, cluster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user