Skip to content

Commit 6feb4ba

Browse files
committed
When turned to using service account for a Sandbox a wrong warning message appears #3878
Fixes: #3878 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent 8f00b81 commit 6feb4ba

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/openshift/cluster.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import fetch = require('make-fetch-happen');
2828

2929
export interface QuickPickItemExt extends QuickPickItem {
3030
name: string,
31-
cluster: string
31+
cluster: string,
32+
user: string,
33+
namespace: string
3234
}
3335

3436
export class Cluster extends OpenShiftItem {
@@ -186,6 +188,8 @@ export class Cluster extends OpenShiftItem {
186188
.map((ctx) => ({
187189
name: `${ctx.name}`,
188190
cluster: `${ctx.cluster}`,
191+
user: `${ctx.user}`,
192+
namespace: `${ctx.namespace}`,
189193
label: `${ctx.label}`,
190194
description: `on ${ctx.cluster}`,
191195
detail: `User: ${ctx.user}`,
@@ -223,8 +227,9 @@ export class Cluster extends OpenShiftItem {
223227
if (await LoginUtil.Instance.requireLogin(clusterURL)) {
224228
const status = await Cluster.login(choice.name, true);
225229
if (status) {
230+
const newKcu = new KubeConfigUtils(); // Can be updated after login
226231
if (Cluster.isSandboxCluster(clusterURL)
227-
&& !k8sConfig.equalsToCurrentContext(choice.name)) {
232+
&& !newKcu.equalsToCurrentContext(choice.name, choice.cluster, choice.namespace, choice.user)) {
228233
await window.showWarningMessage(
229234
'The cluster appears to be a OpenShift Dev Sandbox cluster, \
230235
but the required project doesn\'t appear to be existing. \

src/util/kubeUtils.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,15 @@ export class KubeConfigUtils extends KubeConfig {
128128
return undefined;
129129
}
130130

131-
public equalContexts(c1:string, c2:string): boolean {
132-
if (c1 === c2) return true;
133-
const context1 = this.findContext(c1);
134-
const context2 = this.findContext(c2);
135-
if (context1 === context2) return true; // Both are undefibed or reference the same object
136-
if (context1 === undefined && context2 !== undefined) return false;
137-
if (context1 === undefined && context2 !== undefined) return false;
138-
if (context1.cluster !== context2.cluster) return false;
139-
if (context1.namespace !== context2.namespace) return false;
140-
if (context1.user !== context2.user) return false;
141-
return true;
142-
}
143-
144-
public equalsToCurrentContext(contextName:string): boolean {
131+
public equalsToCurrentContext(contextName:string, cluster: string, namespace: string, user: string): boolean {
145132
const currentContext = this.findContext(this.currentContext);
146133
if (!currentContext) return false;
147134

148-
return this.equalContexts(currentContext.name, contextName);
135+
if (currentContext.name !== contextName) return false;
136+
if (currentContext.cluster !== cluster) return false;
137+
if (currentContext.namespace !== namespace) return false;
138+
if (currentContext.user !== user) return false;
139+
return true;
149140
}
150141
}
151142

0 commit comments

Comments
 (0)