From 59ea59fd99526b5ae5228af9e0087af03c66a0cf Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 28 Jul 2021 15:17:36 -0400 Subject: [PATCH] Fix KubernetesClusters overriding entity names too often Signed-off-by: Sebastian Malton --- src/main/cluster-manager.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 56ce234e90..5338bbad14 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -111,7 +111,15 @@ export class ClusterManager extends Singleton { }; entity.metadata.distro = cluster.distribution; entity.metadata.kubeVersion = cluster.version; - entity.metadata.name = cluster.name; + + if (cluster.preferences?.clusterName) { + /** + * Only set the name if the it is overriden in preferences. If it isn't + * set then the name of the entity has been explicitly set by its source + */ + entity.metadata.name = cluster.preferences.clusterName; + } + entity.spec.metrics ||= { source: "local" }; if (entity.spec.metrics.source === "local") { @@ -164,14 +172,15 @@ export class ClusterManager extends Singleton { if (!cluster) { try { + /** + * Add the bare minimum of data to ClusterStore. And especially no + * preferences, as those might be configured by the entity's source + */ this.store.addCluster({ id: entity.metadata.uid, - preferences: { - clusterName: entity.metadata.name - }, kubeConfigPath: entity.spec.kubeconfigPath, contextName: entity.spec.kubeconfigContext, - accessibleNamespaces: entity.spec.accessibleNamespaces + accessibleNamespaces: entity.spec.accessibleNamespaces ?? [], }); } catch (error) { if (error.code === "ENOENT" && error.path === entity.spec.kubeconfigPath) {