From 96c3d8d3f5892f8d3080b6262889835e9d6a1250 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Tue, 25 May 2021 20:09:04 +0300 Subject: [PATCH] Shorter kubeconfig-sync file label (#2853) * shorter kubeconfig-sync file label Signed-off-by: Jari Kolehmainen * fix tests Signed-off-by: Jari Kolehmainen --- src/main/catalog-sources/__test__/kubeconfig-sync.test.ts | 6 ++++++ src/main/catalog-sources/kubeconfig-sync.ts | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts b/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts index 6f89e12c46..7fcd3c1db6 100644 --- a/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts +++ b/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts @@ -28,6 +28,12 @@ import mockFs from "mock-fs"; import fs from "fs"; import { ClusterStore } from "../../../common/cluster-store"; +jest.mock("electron", () => ({ + app: { + getPath: () => "/foo", + }, +})); + describe("kubeconfig-sync.source tests", () => { beforeEach(() => { mockFs(); diff --git a/src/main/catalog-sources/kubeconfig-sync.ts b/src/main/catalog-sources/kubeconfig-sync.ts index 0f481741d6..c4650644da 100644 --- a/src/main/catalog-sources/kubeconfig-sync.ts +++ b/src/main/catalog-sources/kubeconfig-sync.ts @@ -35,6 +35,7 @@ import { catalogEntityFromCluster } from "../cluster-manager"; import { UserStore } from "../../common/user-store"; import { ClusterStore, UpdateClusterModel } from "../../common/cluster-store"; import { createHash } from "crypto"; +import { homedir } from "os"; const logPrefix = "[KUBECONFIG-SYNC]:"; @@ -193,7 +194,9 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri const entity = catalogEntityFromCluster(cluster); - entity.metadata.labels.file = filePath; + if (!filePath.startsWith(ClusterStore.storedKubeConfigFolder)) { + entity.metadata.labels.file = filePath.replace(homedir(), "~"); + } source.set(contextName, [cluster, entity]); logger.debug(`${logPrefix} Added new cluster from sync`, { filePath, contextName });