From d396f6a44f82d9457468f9b4822c96704881e07c Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Thu, 22 Oct 2020 21:09:15 +0300 Subject: [PATCH] Read cluster id from default namespace Signed-off-by: Lauri Nevala --- src/main/cluster-detectors/cluster-id-detector.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/cluster-detectors/cluster-id-detector.ts b/src/main/cluster-detectors/cluster-id-detector.ts index efeb2badf2..558e52d43c 100644 --- a/src/main/cluster-detectors/cluster-id-detector.ts +++ b/src/main/cluster-detectors/cluster-id-detector.ts @@ -6,7 +6,18 @@ export class ClusterIdDetector extends BaseClusterDetector { key = ClusterMetadataKey.CLUSTER_ID public async detect() { - const id = createHash("sha256").update(this.cluster.apiUrl).digest("hex") - return { value: id, accuracy: 100 } + let id: string + try { + id = await this.getDefaultNamespaceId() + } catch(_) { + id = this.cluster.apiUrl + } + const value = createHash("sha256").update(id).digest("hex") + return { value: value, accuracy: 100 } + } + + protected async getDefaultNamespaceId() { + const response = await this.k8sRequest("/api/v1/namespaces/default") + return response.metadata.uid } } \ No newline at end of file