From 3fc93001538c0d5b44ed89a764d974eeb23dfd67 Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Mon, 5 Feb 2024 19:06:51 +0100 Subject: [PATCH] When turned to using service account for a Sandbox a wrong warning message appears #3878 Fixes: #3878 Signed-off-by: Victor Rubezhny --- src/openshift/cluster.ts | 9 +++++++-- src/util/kubeUtils.ts | 21 ++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/openshift/cluster.ts b/src/openshift/cluster.ts index 15013d37a..b06ddc643 100644 --- a/src/openshift/cluster.ts +++ b/src/openshift/cluster.ts @@ -28,7 +28,9 @@ import fetch = require('make-fetch-happen'); export interface QuickPickItemExt extends QuickPickItem { name: string, - cluster: string + cluster: string, + user: string, + namespace: string } export class Cluster extends OpenShiftItem { @@ -186,6 +188,8 @@ export class Cluster extends OpenShiftItem { .map((ctx) => ({ name: `${ctx.name}`, cluster: `${ctx.cluster}`, + user: `${ctx.user}`, + namespace: `${ctx.namespace}`, label: `${ctx.label}`, description: `on ${ctx.cluster}`, detail: `User: ${ctx.user}`, @@ -223,8 +227,9 @@ export class Cluster extends OpenShiftItem { if (await LoginUtil.Instance.requireLogin(clusterURL)) { const status = await Cluster.login(choice.name, true); if (status) { + const newKcu = new KubeConfigUtils(); // Can be updated after login if (Cluster.isSandboxCluster(clusterURL) - && !k8sConfig.equalsToCurrentContext(choice.name)) { + && !newKcu.equalsToCurrentContext(choice.name, choice.cluster, choice.namespace, choice.user)) { await window.showWarningMessage( 'The cluster appears to be a OpenShift Dev Sandbox cluster, \ but the required project doesn\'t appear to be existing. \ diff --git a/src/util/kubeUtils.ts b/src/util/kubeUtils.ts index 3ba188b9f..694b3a329 100644 --- a/src/util/kubeUtils.ts +++ b/src/util/kubeUtils.ts @@ -128,24 +128,15 @@ export class KubeConfigUtils extends KubeConfig { return undefined; } - public equalContexts(c1:string, c2:string): boolean { - if (c1 === c2) return true; - const context1 = this.findContext(c1); - const context2 = this.findContext(c2); - if (context1 === context2) return true; // Both are undefibed or reference the same object - if (context1 === undefined && context2 !== undefined) return false; - if (context1 === undefined && context2 !== undefined) return false; - if (context1.cluster !== context2.cluster) return false; - if (context1.namespace !== context2.namespace) return false; - if (context1.user !== context2.user) return false; - return true; - } - - public equalsToCurrentContext(contextName:string): boolean { + public equalsToCurrentContext(contextName:string, cluster: string, namespace: string, user: string): boolean { const currentContext = this.findContext(this.currentContext); if (!currentContext) return false; - return this.equalContexts(currentContext.name, contextName); + if (currentContext.name !== contextName) return false; + if (currentContext.cluster !== cluster) return false; + if (currentContext.namespace !== namespace) return false; + if (currentContext.user !== user) return false; + return true; } }