mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
redid changes after large refactor on master (#4688)
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
23c38b1f4e
commit
6cba82c491
@ -14,11 +14,10 @@ export class PortForwardRoute {
|
|||||||
const { namespace, resourceType, resourceName } = params;
|
const { namespace, resourceType, resourceName } = params;
|
||||||
const port = Number(query.get("port"));
|
const port = Number(query.get("port"));
|
||||||
const forwardPort = Number(query.get("forwardPort"));
|
const forwardPort = Number(query.get("forwardPort"));
|
||||||
const protocol = query.get("protocol");
|
|
||||||
|
|
||||||
const portForward = PortForward.getPortforward({
|
const portForward = PortForward.getPortforward({
|
||||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||||
namespace, port, forwardPort, protocol,
|
namespace, port, forwardPort,
|
||||||
});
|
});
|
||||||
|
|
||||||
respondJson(response, { port: portForward?.forwardPort ?? null });
|
respondJson(response, { port: portForward?.forwardPort ?? null });
|
||||||
|
|||||||
@ -16,7 +16,6 @@ export interface PortForwardArgs {
|
|||||||
name: string;
|
name: string;
|
||||||
port: number;
|
port: number;
|
||||||
forwardPort: number;
|
forwardPort: number;
|
||||||
protocol?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
@ -32,8 +31,7 @@ export class PortForward {
|
|||||||
pf.kind == forward.kind &&
|
pf.kind == forward.kind &&
|
||||||
pf.name == forward.name &&
|
pf.name == forward.name &&
|
||||||
pf.namespace == forward.namespace &&
|
pf.namespace == forward.namespace &&
|
||||||
pf.port == forward.port &&
|
pf.port == forward.port
|
||||||
(!forward.protocol || pf.protocol == forward.protocol)
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +42,6 @@ export class PortForward {
|
|||||||
public name: string;
|
public name: string;
|
||||||
public port: number;
|
public port: number;
|
||||||
public forwardPort: number;
|
public forwardPort: number;
|
||||||
public protocol: string;
|
|
||||||
|
|
||||||
constructor(private dependencies: Dependencies, public pathToKubeConfig: string, args: PortForwardArgs) {
|
constructor(private dependencies: Dependencies, public pathToKubeConfig: string, args: PortForwardArgs) {
|
||||||
this.clusterId = args.clusterId;
|
this.clusterId = args.clusterId;
|
||||||
@ -53,7 +50,6 @@ export class PortForward {
|
|||||||
this.name = args.name;
|
this.name = args.name;
|
||||||
this.port = args.port;
|
this.port = args.port;
|
||||||
this.forwardPort = args.forwardPort;
|
this.forwardPort = args.forwardPort;
|
||||||
this.protocol = args.protocol ?? "http";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
|
|||||||
@ -18,7 +18,6 @@ export const routePortForward =
|
|||||||
const { namespace, resourceType, resourceName } = params;
|
const { namespace, resourceType, resourceName } = params;
|
||||||
const port = Number(query.get("port"));
|
const port = Number(query.get("port"));
|
||||||
const forwardPort = Number(query.get("forwardPort"));
|
const forwardPort = Number(query.get("forwardPort"));
|
||||||
const protocol = query.get("protocol");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let portForward = PortForward.getPortforward({
|
let portForward = PortForward.getPortforward({
|
||||||
@ -28,7 +27,6 @@ export const routePortForward =
|
|||||||
namespace,
|
namespace,
|
||||||
port,
|
port,
|
||||||
forwardPort,
|
forwardPort,
|
||||||
protocol,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!portForward) {
|
if (!portForward) {
|
||||||
@ -46,7 +44,6 @@ export const routePortForward =
|
|||||||
name: resourceName,
|
name: resourceName,
|
||||||
port,
|
port,
|
||||||
forwardPort: thePort,
|
forwardPort: thePort,
|
||||||
protocol,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const started = await portForward.start();
|
const started = await portForward.start();
|
||||||
|
|||||||
@ -273,11 +273,9 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
|||||||
let response: PortForwardResult;
|
let response: PortForwardResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const protocol = pf.protocol ?? "http";
|
|
||||||
|
|
||||||
response = await apiBase.post<PortForwardResult>(
|
response = await apiBase.post<PortForwardResult>(
|
||||||
`/pods/port-forward/${pf.namespace}/${pf.kind}/${pf.name}`,
|
`/pods/port-forward/${pf.namespace}/${pf.kind}/${pf.name}`,
|
||||||
{ query: { port, forwardPort, protocol }},
|
{ query: { port, forwardPort }},
|
||||||
);
|
);
|
||||||
|
|
||||||
// expecting the received port to be the specified port, unless the specified port is 0, which indicates any available port is suitable
|
// expecting the received port to be the specified port, unless the specified port is 0, which indicates any available port is suitable
|
||||||
@ -355,11 +353,11 @@ function portForwardsEqual(portForward: ForwardedPort) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getActivePortForward(portForward: ForwardedPort): Promise<ForwardedPort> {
|
async function getActivePortForward(portForward: ForwardedPort): Promise<ForwardedPort> {
|
||||||
const { port, forwardPort, protocol } = portForward;
|
const { port, forwardPort } = portForward;
|
||||||
let response: PortForwardResult;
|
let response: PortForwardResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}`, { query: { port, forwardPort, protocol }});
|
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}`, { query: { port, forwardPort }});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`[PORT-FORWARD-STORE] Error getting active port-forward: ${error}`, portForward);
|
logger.warn(`[PORT-FORWARD-STORE] Error getting active port-forward: ${error}`, portForward);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user