From 43a31c37bee23d24bc6b465c99e3f14c2db54986 Mon Sep 17 00:00:00 2001 From: Jessica He Date: Fri, 23 Jun 2023 15:15:04 -0400 Subject: [PATCH] Add check for OpenShift cluster when opening developer console Signed-off-by: Jessica He --- package.json | 4 ++-- src/explorer.ts | 7 +++++++ src/odo/command.ts | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 24b474761..2fbf9138a 100644 --- a/package.json +++ b/package.json @@ -1211,7 +1211,7 @@ }, { "command": "openshift.open.developerConsole", - "when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext", + "when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext && isOpenshiftCluster", "group": "c0" }, { @@ -1385,7 +1385,7 @@ }, { "command": "openshift.resource.openInDeveloperConsole", - "when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject || viewItem == openshift.k8sObject.helm" + "when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject && isOpenshiftCluster || openshift.k8sObject.helm && isOpenshiftCluster" } ] }, diff --git a/src/explorer.ts b/src/explorer.ts index 89facf757..de3044f0f 100644 --- a/src/explorer.ts +++ b/src/explorer.ts @@ -231,6 +231,13 @@ export class OpenShiftExplorer implements TreeDataProvider, Dispos } else { result = [...await this.odo3.getDeploymentConfigs(), ...await this.odo3.getDeployments()]; } + // don't show Open In Developer Dashboard if not openshift cluster + const openshiftResources = await CliChannel.getInstance().executeTool(Command.isOpenshiftCluster()); + let isOpenshiftCluster = true; + if (openshiftResources.stdout.length === 0){ + isOpenshiftCluster = false; + } + void commands.executeCommand('setContext', 'isOpenshiftCluster', isOpenshiftCluster); if (!element) { await commands.executeCommand('setContext', 'openshift.app.explorer.init', result.length === 0); diff --git a/src/odo/command.ts b/src/odo/command.ts index ce27e1f78..e6f1972d8 100644 --- a/src/odo/command.ts +++ b/src/odo/command.ts @@ -315,4 +315,9 @@ export class Command { static canCreatePod(): CommandText { return new CommandText('oc auth can-i create pod'); } + + static isOpenshiftCluster(): CommandText { + return new CommandText('oc api-resources | grep openshift'); + } + }