From e71ee755818facfcf42789da2dbbe0f40657a346 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 15 Jul 2021 16:28:44 -0400 Subject: [PATCH] Catch Cluster create error in cluster-manager - Only warn if the file is missing. The file must have disapeared betweeen kubeconfig-sync detecting it and cluster-manager performing the addCluster call - For all other errors log an error Signed-off-by: Sebastian Malton --- src/main/cluster-manager.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 73d2c50f46..cbe8127353 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -161,14 +161,22 @@ export class ClusterManager extends Singleton { const cluster = this.store.getById(entity.metadata.uid); if (!cluster) { - this.store.addCluster({ - id: entity.metadata.uid, - preferences: { - clusterName: entity.metadata.name - }, - kubeConfigPath: entity.spec.kubeconfigPath, - contextName: entity.spec.kubeconfigContext - }); + try { + this.store.addCluster({ + id: entity.metadata.uid, + preferences: { + clusterName: entity.metadata.name + }, + kubeConfigPath: entity.spec.kubeconfigPath, + contextName: entity.spec.kubeconfigContext + }); + } catch (error) { + if (error.code === "ENOENT" && error.path === entity.spec.kubeconfigPath) { + console.warn("[CLUSTER-MANGER]: kubeconfig file disappeared", { path: entity.spec.kubeconfigPath }); + } else { + console.error(`[CLUSTER-MANAGER]: failed to add cluster: ${error}`); + } + } } else { cluster.kubeConfigPath = entity.spec.kubeconfigPath; cluster.contextName = entity.spec.kubeconfigContext;