Skip to content

Commit 70ca0a4

Browse files
committed
Use config parser when it is in function scope
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 69cb65e commit 70ca0a4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/k8s/console.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import { KubeConfigUtils } from "../util/kubeUtils";
1111
import { OpenShiftItem } from '../openshift/openshiftItem';
1212
import { CliExitData } from '../cli';
1313

14-
const k8sConfig = new KubeConfigUtils();
15-
const project = (k8sConfig.contexts).find((ctx) => ctx.name === k8sConfig.currentContext).namespace;
16-
1714
export class Console extends OpenShiftItem {
1815

16+
static getCurrentProject() {
17+
const k8sConfig = new KubeConfigUtils();
18+
const project = (k8sConfig.contexts).find((ctx) => ctx.name === k8sConfig.currentContext).namespace;
19+
return project;
20+
}
21+
1922
static async fetchOpenshiftConsoleUrl() {
2023
try {
2124
return await Console.odo.execute(Command.showConsoleUrl());
@@ -36,6 +39,7 @@ export class Console extends OpenShiftItem {
3639
return;
3740
}
3841
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
42+
const project = Console.getCurrentProject();
3943
if (consoleUrl['stdout']) {
4044
url = `${Console.openShift4ClusterUrl(consoleUrl)}/k8s/ns/${project}/buildconfigs/${context.name}`;
4145
} else {
@@ -50,6 +54,7 @@ export class Console extends OpenShiftItem {
5054
vscode.window.showErrorMessage("Cannot load the deployment config");
5155
return;
5256
}
57+
const project = Console.getCurrentProject();
5358
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
5459
if (consoleUrl['stdout']) {
5560
url = `${Console.openShift4ClusterUrl(consoleUrl)}/k8s/ns/${project}/deploymentconfigs/${context.name}`;
@@ -65,6 +70,7 @@ export class Console extends OpenShiftItem {
6570
vscode.window.showErrorMessage("Cannot load the image stream");
6671
return;
6772
}
73+
const project = Console.getCurrentProject();
6874
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
6975
if (consoleUrl['stdout']) {
7076
url = `${Console.openShift4ClusterUrl(consoleUrl)}/k8s/ns/${project}/imagestreams/${context.name}`;
@@ -80,6 +86,7 @@ export class Console extends OpenShiftItem {
8086
vscode.window.showErrorMessage("Cannot load the Project");
8187
return;
8288
}
89+
const project = Console.getCurrentProject();
8390
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
8491
if (consoleUrl['stdout']) {
8592
url = `${Console.openShift4ClusterUrl(consoleUrl)}/k8s/cluster/projects/${project}`;

0 commit comments

Comments
 (0)