Skip to content

Commit 46b1101

Browse files
mohitsumandgolovin
authored andcommitted
fix list of urls in Open in Browser action (#1152)
* fix list of urls in Open in Browser action * fix tslint issue for unused variables
1 parent 5f7c022 commit 46b1101

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

src/odo.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ export class Command {
179179
static watchComponent(project: string, app: string, component: string) {
180180
return `odo watch ${component} --app ${app} --project ${project}`;
181181
}
182-
static getRouteHostName(namespace: string, component: string) {
183-
return `oc get route --namespace ${namespace} -o jsonpath="{range .items[?(.metadata.labels.app\\.kubernetes\\.io/instance=='${component}')]}{.spec.host}{end}"`;
184-
}
185182
@verbose
186183
static createLocalComponent(project: string, app: string, type: string, version: string, name: string, folder: string) {
187184
return `odo create ${type}:${version} ${name} --context ${folder} --app ${app} --project ${project}`;
@@ -211,7 +208,7 @@ export class Command {
211208
static createComponentCustomUrl(name: string, port: string) {
212209
return `odo url create ${name} --port ${port}`;
213210
}
214-
static getComponentUrl(project: string, app: string, component: string) {
211+
static getComponentUrl() {
215212
return `odo url list -o json`;
216213
}
217214
static deleteComponentUrl(project: string, app: string, component: string, name: string) {
@@ -746,8 +743,7 @@ export class OdoImpl implements Odo {
746743
}
747744

748745
public async _getRoutes(component: OpenShiftObject): Promise<OpenShiftObject[]> {
749-
const app = component.getParent();
750-
const result: cliInstance.CliExitData = await this.execute(Command.getComponentUrl(app.getParent().getName(), app.getName(), component.getName()), component.contextPath ? component.contextPath.fsPath : Platform.getUserHomePath(), false);
746+
const result: cliInstance.CliExitData = await this.execute(Command.getComponentUrl(), component.contextPath ? component.contextPath.fsPath : Platform.getUserHomePath(), false);
751747
return this.loadItems(result).map((value) => new OpenShiftObjectImpl(component, value.metadata.name, ContextType.COMPONENT_ROUTE, false, OdoImpl.instance, TreeItemCollapsibleState.None));
752748
}
753749

src/openshift/component.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,24 +348,17 @@ export class Component extends OpenShiftItem {
348348
);
349349
if (!component) return null;
350350
const app: OpenShiftObject = component.getParent();
351-
const namespace: string = app.getParent().getName();
352-
if (await Component.checkRouteCreated(namespace, component)) {
351+
const urlItems = await Component.listUrl(component);
352+
if (urlItems === null) {
353353
const value = await window.showInformationMessage(`No URL for Component '${component.getName()}' in Application '${app.getName()}'. Do you want to create a URL and open it?`, 'Create', 'Cancel');
354354
if (value === 'Create') {
355355
await commands.executeCommand('openshift.url.create', component);
356356
}
357357
}
358358

359-
if (! await Component.checkRouteCreated(namespace, component)) {
360-
const UrlDetails = await Component.odo.execute(Command.getComponentUrl(namespace, app.getName(), component.getName()), component.contextPath.fsPath);
361-
let result: any[] = [];
359+
if (urlItems !== null) {
362360
let selectRoute: QuickPickItem;
363-
try {
364-
result = JSON.parse(UrlDetails.stdout).items;
365-
} catch (ignore) {
366-
// should give empty list if no url configured
367-
// see https://github.com/openshift/odo/issues/1515
368-
}
361+
const result = urlItems.filter(value => value.status.state === 'Pushed');
369362
const hostName: QuickPickItem[] = result.map((value) => ({ label: `${value.spec.protocol}://${value.spec.host}`, description: `Target Port is ${value.spec.port}`}));
370363
if (hostName.length >1) {
371364
selectRoute = await window.showQuickPick(hostName, {placeHolder: "This Component has multiple URLs. Select the desired URL to open in browser."});
@@ -377,9 +370,9 @@ export class Component extends OpenShiftItem {
377370
}
378371
}
379372

380-
static async checkRouteCreated(namespace: string, component: OpenShiftObject): Promise<boolean> {
381-
const routeCheck = await Component.odo.execute(Command.getRouteHostName(namespace, component.getName()));
382-
return routeCheck.stdout.trim() === '';
373+
static async listUrl(component: OpenShiftObject) {
374+
const UrlDetails = await Component.odo.execute(Command.getComponentUrl(), component.contextPath.fsPath);
375+
return JSON.parse(UrlDetails.stdout).items;
383376
}
384377

385378
static async createFromLocal(context: OpenShiftObject): Promise<string> {

src/openshift/url.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ export class Url extends OpenShiftItem{
6868

6969
static async open(treeItem: OpenShiftObject): Promise<ChildProcess> {
7070
const component = treeItem.getParent();
71-
const app = component.getParent();
72-
const namespace = app.getParent();
73-
const urlDetails = await Url.odo.execute(Command.getComponentUrl(namespace.getName(), app.getName(), component.getName()), component.contextPath.fsPath);
71+
const urlDetails = await Url.odo.execute(Command.getComponentUrl(), component.contextPath.fsPath);
7472
let urlObject: any;
7573
let result: any[];
7674
try {

0 commit comments

Comments
 (0)