mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Added ability to add custom port on pod and service port forwarding
Signed-off-by: rdeepc <12953177+rdeepc@users.noreply.github.com>
This commit is contained in:
parent
394ca5432d
commit
2376695e1d
@ -45,10 +45,10 @@ class PortForward {
|
||||
static getPortforward(forward: PortForwardArgs) {
|
||||
return PortForward.portForwards.find((pf) => (
|
||||
pf.clusterId == forward.clusterId &&
|
||||
pf.kind == forward.kind &&
|
||||
pf.name == forward.name &&
|
||||
pf.namespace == forward.namespace &&
|
||||
pf.port == forward.port
|
||||
pf.kind == forward.kind &&
|
||||
pf.name == forward.name &&
|
||||
pf.namespace == forward.namespace &&
|
||||
pf.port == forward.port
|
||||
));
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ class PortForward {
|
||||
public name: string;
|
||||
public port: string;
|
||||
public internalPort?: number;
|
||||
public forwardPort?: string;
|
||||
public forwardPort: string;
|
||||
|
||||
constructor(public kubeConfig: string, args: PortForwardArgs) {
|
||||
this.clusterId = args.clusterId;
|
||||
@ -156,7 +156,7 @@ export class PortForwardRoute {
|
||||
|
||||
portForward.open();
|
||||
respondJson(response, {port: portForward.forwardPort});
|
||||
} catch (error) {
|
||||
} catch (e) {
|
||||
return respondJson(response, {
|
||||
message: `Failed to forward port ${port} to ${forwardPort}`
|
||||
}, 400);
|
||||
@ -172,7 +172,11 @@ export class PortForwardRoute {
|
||||
namespace, port, forwardPort
|
||||
});
|
||||
|
||||
const forwardedPort = portForward?.forwardPort?? null;
|
||||
let forwardedPort = -1;
|
||||
|
||||
if (portForward) {
|
||||
forwardedPort = Number(portForward.forwardPort);
|
||||
}
|
||||
|
||||
respondJson(response, {port: forwardedPort});
|
||||
}
|
||||
@ -186,11 +190,8 @@ export class PortForwardRoute {
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
try {
|
||||
await portForward.stop();
|
||||
portForward.stop().then( () => {
|
||||
respondJson(response, {status: true});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
}).catch(error => logger.error(error));
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ interface PortForwardResult {
|
||||
@observer
|
||||
export class ServicePortComponent extends React.Component<Props> {
|
||||
@observable waiting = false;
|
||||
@observable forwardPort: number | null;
|
||||
@observable forwardPort = -1;
|
||||
@observable isPortForwarded = false;
|
||||
|
||||
constructor(props: Props) {
|
||||
@ -53,9 +53,7 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
}
|
||||
|
||||
init() {
|
||||
this.checkExistingPortForwarding().catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
this.checkExistingPortForwarding().then();
|
||||
}
|
||||
|
||||
async checkExistingPortForwarding() {
|
||||
@ -64,7 +62,7 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
|
||||
const activePort = response.port;
|
||||
|
||||
if (activePort) {
|
||||
if (activePort && activePort != -1) {
|
||||
this.forwardPort = activePort;
|
||||
this.isPortForwarded = true;
|
||||
}
|
||||
@ -80,6 +78,7 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
|
||||
this.forwardPort = response.port;
|
||||
this.isPortForwarded = true;
|
||||
|
||||
} catch(error) {
|
||||
Notifications.error(error);
|
||||
} finally {
|
||||
@ -105,7 +104,7 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
render() {
|
||||
const { port } = this.props;
|
||||
|
||||
if (this.forwardPort == null) {
|
||||
if (this.forwardPort == -1) {
|
||||
this.forwardPort = port.port;
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ interface PortForwardResult {
|
||||
@observer
|
||||
export class PodContainerPort extends React.Component<Props> {
|
||||
@observable waiting = false;
|
||||
@observable forwardPort: number | null;
|
||||
@observable forwardPort = -1;
|
||||
@observable isPortForwarded = false;
|
||||
|
||||
constructor(props: Props) {
|
||||
@ -57,9 +57,7 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
}
|
||||
|
||||
init() {
|
||||
this.checkExistingPortForwarding().catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
this.checkExistingPortForwarding().then();
|
||||
}
|
||||
|
||||
async checkExistingPortForwarding() {
|
||||
@ -68,7 +66,7 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
|
||||
const activePort = response.port;
|
||||
|
||||
if (activePort) {
|
||||
if (activePort && activePort != -1) {
|
||||
this.forwardPort = activePort;
|
||||
this.isPortForwarded = true;
|
||||
}
|
||||
@ -111,14 +109,14 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
const { name, containerPort, protocol } = port;
|
||||
const text = `${name ? `${name}: ` : ""}${containerPort}/${protocol}`;
|
||||
|
||||
if (this.forwardPort == null) {
|
||||
if (this.forwardPort == -1) {
|
||||
this.forwardPort = containerPort;
|
||||
}
|
||||
|
||||
const portForwardAction = async () => {
|
||||
if (this.isPortForwarded) {
|
||||
await this.stopPortForward();
|
||||
} else {
|
||||
}else {
|
||||
await this.portForward();
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user