mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
changed port and forwardPort fields to be Numbers
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
58314945ed
commit
9a547973bc
@ -32,8 +32,8 @@ interface PortForwardArgs {
|
||||
kind: string;
|
||||
namespace: string;
|
||||
name: string;
|
||||
port: string;
|
||||
forwardPort: string;
|
||||
port: number;
|
||||
forwardPort: number;
|
||||
}
|
||||
|
||||
const internalPortRegex = /^forwarding from (?<address>.+) ->/i;
|
||||
@ -56,9 +56,9 @@ class PortForward {
|
||||
public kind: string;
|
||||
public namespace: string;
|
||||
public name: string;
|
||||
public port: string;
|
||||
public port: number;
|
||||
public internalPort?: number;
|
||||
public forwardPort?: string;
|
||||
public forwardPort?: number;
|
||||
|
||||
constructor(public kubeConfig: string, args: PortForwardArgs) {
|
||||
this.clusterId = args.clusterId;
|
||||
@ -98,7 +98,7 @@ class PortForward {
|
||||
try {
|
||||
await tcpPortUsed.waitUntilUsed(this.internalPort, 500, 15000);
|
||||
|
||||
this.forwardPort = String(this.internalPort);
|
||||
this.forwardPort = this.internalPort;
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
@ -117,8 +117,8 @@ export class PortForwardRoute {
|
||||
static async routePortForward(request: LensApiRequest) {
|
||||
const { params, query, response, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = query.get("port");
|
||||
const forwardPort = query.get("forwardPort");
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
try {
|
||||
let portForward = PortForward.getPortforward({
|
||||
@ -126,10 +126,9 @@ export class PortForwardRoute {
|
||||
namespace, port, forwardPort,
|
||||
});
|
||||
|
||||
let thePort: string; // undefined
|
||||
const portNum = Number(forwardPort);
|
||||
let thePort = 0;
|
||||
|
||||
if (portNum > 0 && portNum < 65536) {
|
||||
if (forwardPort > 0 && forwardPort < 65536) {
|
||||
thePort = forwardPort;
|
||||
}
|
||||
|
||||
@ -168,8 +167,8 @@ export class PortForwardRoute {
|
||||
static async routeCurrentPortForward(request: LensApiRequest) {
|
||||
const { params, query, response, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = query.get("port");
|
||||
const forwardPort = query.get("forwardPort");
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
@ -199,8 +198,8 @@ export class PortForwardRoute {
|
||||
static async routeCurrentPortForwardStop(request: LensApiRequest) {
|
||||
const { params, query, response, cluster } = request;
|
||||
const { namespace, resourceType, resourceName } = params;
|
||||
const port = query.get("port");
|
||||
const forwardPort = query.get("forwardPort");
|
||||
const port = Number(query.get("port"));
|
||||
const forwardPort = Number(query.get("forwardPort"));
|
||||
|
||||
const portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
|
||||
@ -68,8 +68,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
kind: "service",
|
||||
name: service.getName(),
|
||||
namespace: service.getNs(),
|
||||
port: port.port.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.port,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
const activePort = await getPortForward(portForward) ?? 0;
|
||||
|
||||
@ -83,8 +83,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
kind: "service",
|
||||
name: service.getName(),
|
||||
namespace: service.getNs(),
|
||||
port: port.port.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.port,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
this.waiting = true;
|
||||
@ -97,7 +97,7 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
this.forwardPort = await addPortForward(portForward);
|
||||
|
||||
if (this.forwardPort) {
|
||||
portForward.forwardPort = this.forwardPort.toString();
|
||||
portForward.forwardPort = this.forwardPort;
|
||||
openPortForward(portForward);
|
||||
this.isPortForwarded = true;
|
||||
}
|
||||
@ -114,8 +114,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
kind: "service",
|
||||
name: service.getName(),
|
||||
namespace: service.getNs(),
|
||||
port: port.port.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.port,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
this.waiting = true;
|
||||
@ -141,8 +141,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
||||
kind: "service",
|
||||
name: service.getName(),
|
||||
namespace: service.getNs(),
|
||||
port: port.port.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.port,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
PortForwardDialog.open(portForward, { openInBrowser: true });
|
||||
|
||||
@ -72,8 +72,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
kind: "pod",
|
||||
name: pod.getName(),
|
||||
namespace: pod.getNs(),
|
||||
port: port.containerPort.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.containerPort,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
const activePort = await getPortForward(portForward) ?? 0;
|
||||
|
||||
@ -87,8 +87,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
kind: "pod",
|
||||
name: pod.getName(),
|
||||
namespace: pod.getNs(),
|
||||
port: port.containerPort.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.containerPort,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
this.waiting = true;
|
||||
@ -101,7 +101,7 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
this.forwardPort = await addPortForward(portForward);
|
||||
|
||||
if (this.forwardPort) {
|
||||
portForward.forwardPort = this.forwardPort.toString();
|
||||
portForward.forwardPort = this.forwardPort;
|
||||
openPortForward(portForward);
|
||||
this.isPortForwarded = true;
|
||||
}
|
||||
@ -118,8 +118,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
kind: "pod",
|
||||
name: pod.getName(),
|
||||
namespace: pod.getNs(),
|
||||
port: port.containerPort.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.containerPort,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
this.waiting = true;
|
||||
@ -147,8 +147,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
kind: "pod",
|
||||
name: pod.getName(),
|
||||
namespace: pod.getNs(),
|
||||
port: port.containerPort.toString(),
|
||||
forwardPort: this.forwardPort.toString()
|
||||
port: port.containerPort,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
|
||||
PortForwardDialog.open(portForward, { openInBrowser: true });
|
||||
|
||||
@ -102,12 +102,12 @@ export class PortForwardDialog extends Component<Props> {
|
||||
if (currentPort) {
|
||||
port = await modifyPortForward(portForward, desiredPort);
|
||||
} else {
|
||||
portForward.forwardPort = String(desiredPort);
|
||||
portForward.forwardPort = desiredPort;
|
||||
port = await addPortForward(portForward);
|
||||
}
|
||||
|
||||
if (dialogState.openInBrowser) {
|
||||
portForward.forwardPort = String(port);
|
||||
portForward.forwardPort = port;
|
||||
openPortForward(portForward);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@ -28,8 +28,8 @@ export interface ForwardedPort {
|
||||
kind: string;
|
||||
namespace: string;
|
||||
name: string;
|
||||
port: string;
|
||||
forwardPort: string;
|
||||
port: number;
|
||||
forwardPort: number;
|
||||
}
|
||||
|
||||
export class PortForwardItem implements ItemObject {
|
||||
@ -37,8 +37,8 @@ export class PortForwardItem implements ItemObject {
|
||||
kind: string;
|
||||
namespace: string;
|
||||
name: string;
|
||||
port: string;
|
||||
forwardPort: string;
|
||||
port: number;
|
||||
forwardPort: number;
|
||||
|
||||
constructor(pf: ForwardedPort) {
|
||||
this.clusterId = pf.clusterId;
|
||||
@ -64,7 +64,7 @@ export class PortForwardItem implements ItemObject {
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.forwardPort;
|
||||
return String(this.forwardPort);
|
||||
}
|
||||
|
||||
getKind() {
|
||||
|
||||
@ -127,7 +127,7 @@ export async function modifyPortForward(portForward: ForwardedPort, desiredPort:
|
||||
|
||||
try {
|
||||
await removePortForward(portForward);
|
||||
portForward.forwardPort = desiredPort.toString();
|
||||
portForward.forwardPort = desiredPort;
|
||||
port = await addPortForward(portForward);
|
||||
} catch (error) {
|
||||
logger.warn(error); // don't care, caller must check
|
||||
|
||||
Loading…
Reference in New Issue
Block a user