Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/openshift/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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. \
Expand Down
21 changes: 6 additions & 15 deletions src/util/kubeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down