Skip to content

Commit b06bcc1

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 eb06f1c commit b06bcc1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,22 @@ export class KubeConfigUtils extends KubeConfig {
134134
const context2 = this.findContext(c2);
135135
if (context1 === context2) return true; // Both are undefibed or reference the same object
136136
if (context1 === undefined && context2 !== undefined) return false;
137-
if (context1 === undefined && context2 !== undefined) return false;
137+
if (context2 === undefined && context1 !== undefined) return false;
138138
if (context1.cluster !== context2.cluster) return false;
139139
if (context1.namespace !== context2.namespace) return false;
140140
if (context1.user !== context2.user) return false;
141141
return true;
142142
}
143143

144-
public equalsToCurrentContext(contextName:string): boolean {
144+
public equalsToCurrentContext(contextName:string, cluster: string, namespace: string, user: string): boolean {
145145
const currentContext = this.findContext(this.currentContext);
146146
if (!currentContext) return false;
147147

148-
return this.equalContexts(currentContext.name, contextName);
148+
if (currentContext.name !== contextName) return false;
149+
if (currentContext.cluster !== cluster) return false;
150+
if (currentContext.namespace !== namespace) return false;
151+
if (currentContext.user !== user) return false;
152+
return true;
149153
}
150154
}
151155

0 commit comments

Comments
 (0)