1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Read cluster id from default namespace

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-10-22 21:09:15 +03:00
parent 6477d5b4d2
commit d396f6a44f

View File

@ -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
}
}