Skip to content

Commit ff79fd3

Browse files
committed
Implement port selection when linking component with multiple ports
1 parent 2e70650 commit ff79fd3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/openshift/component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ChildProcess } from 'child_process';
1212
import * as validator from 'validator';
1313
import { Url } from './url';
1414
import { Service } from './service';
15+
import { CliExitData } from '../cli';
1516
export class Component extends OpenShiftItem {
1617
static async create(application: OpenShiftObject): Promise<string> {
1718
// should use QuickPickItem with label and description
@@ -101,8 +102,20 @@ export class Component extends OpenShiftItem {
101102
const componentToLink = await vscode.window.showQuickPick(componentPresent.filter((comp)=> comp.getName() !== context.getName()), {placeHolder: "Select the component to link"});
102103
if (!componentToLink) return null;
103104

105+
const portsResult: CliExitData = await Component.odo.execute(`oc get service ${componentToLink.getName()}-${app.getName()} --namespace ${project.getName()} -o jsonpath="{range .spec.ports[*]}{.port}{','}{end}"`);
106+
let ports: string[] = portsResult.stdout.trim().split(',');
107+
ports = ports.slice(0, ports.length-1);
108+
let port: string;
109+
if (ports.length === 1) {
110+
port = ports[0];
111+
} else if (ports.length > 1) {
112+
port = await vscode.window.showQuickPick(ports, {placeHolder: "Select port to link"});
113+
} else {
114+
return Promise.reject(`Component '${context.getName()}' has no ports decalred.`);
115+
}
116+
104117
return Promise.resolve()
105-
.then(() => Component.odo.execute(`odo link ${componentToLink.getName()} --app ${app.getName()} --project ${project.getName()} --component ${context.getName()} --wait`))
118+
.then(() => Component.odo.execute(`odo project set ${project.getName()} && odo application set ${app.getName()} && odo component set ${context.getName()} && odo link ${componentToLink.getName()} --port ${port} --wait`))
106119
.then(() => `component '${componentToLink.getName()}' successfully linked with component '${context.getName()}'`)
107120
.catch((err) => Promise.reject(`Failed to link component with error '${err}'`));
108121
}

0 commit comments

Comments
 (0)