mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Enforce semicolons in eslint
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
0f3f5611ba
commit
1477bb8274
531 files changed
+3979
-3975
No files matched your search
@@ -1,11 +1,11 @@
|
||||
import { LensApiRequest } from "../router"
|
||||
import { LensApi } from "../lens-api"
|
||||
import { spawn, ChildProcessWithoutNullStreams } from "child_process"
|
||||
import { Kubectl } from "../kubectl"
|
||||
import { getFreePort } from "../port"
|
||||
import { shell } from "electron"
|
||||
import * as tcpPortUsed from "tcp-port-used"
|
||||
import logger from "../logger"
|
||||
import { LensApiRequest } from "../router";
|
||||
import { LensApi } from "../lens-api";
|
||||
import { spawn, ChildProcessWithoutNullStreams } from "child_process";
|
||||
import { Kubectl } from "../kubectl";
|
||||
import { getFreePort } from "../port";
|
||||
import { shell } from "electron";
|
||||
import * as tcpPortUsed from "tcp-port-used";
|
||||
import logger from "../logger";
|
||||
|
||||
class PortForward {
|
||||
public static portForwards: PortForward[] = []
|
||||
@@ -18,8 +18,8 @@ class PortForward {
|
||||
pf.name == forward.name &&
|
||||
pf.namespace == forward.namespace &&
|
||||
pf.port == forward.port
|
||||
)
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public clusterId: string
|
||||
@@ -32,56 +32,56 @@ class PortForward {
|
||||
public localPort: number
|
||||
|
||||
constructor(obj: any) {
|
||||
Object.assign(this, obj)
|
||||
Object.assign(this, obj);
|
||||
}
|
||||
|
||||
public async start() {
|
||||
this.localPort = await getFreePort()
|
||||
const kubectlBin = await Kubectl.bundled().getPath()
|
||||
this.localPort = await getFreePort();
|
||||
const kubectlBin = await Kubectl.bundled().getPath();
|
||||
const args = [
|
||||
"--kubeconfig", this.kubeConfig,
|
||||
"port-forward",
|
||||
"-n", this.namespace,
|
||||
`${this.kind}/${this.name}`,
|
||||
`${this.localPort}:${this.port}`
|
||||
]
|
||||
];
|
||||
|
||||
this.process = spawn(kubectlBin, args, {
|
||||
env: process.env
|
||||
})
|
||||
PortForward.portForwards.push(this)
|
||||
});
|
||||
PortForward.portForwards.push(this);
|
||||
this.process.on("exit", () => {
|
||||
const index = PortForward.portForwards.indexOf(this)
|
||||
const index = PortForward.portForwards.indexOf(this);
|
||||
if (index > -1) {
|
||||
PortForward.portForwards.splice(index, 1)
|
||||
PortForward.portForwards.splice(index, 1);
|
||||
}
|
||||
})
|
||||
});
|
||||
try {
|
||||
await tcpPortUsed.waitUntilUsed(this.localPort, 500, 15000)
|
||||
return true
|
||||
await tcpPortUsed.waitUntilUsed(this.localPort, 500, 15000);
|
||||
return true;
|
||||
} catch (error) {
|
||||
this.process.kill()
|
||||
return false
|
||||
this.process.kill();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public open() {
|
||||
shell.openExternal(`http://localhost:${this.localPort}`)
|
||||
shell.openExternal(`http://localhost:${this.localPort}`);
|
||||
}
|
||||
}
|
||||
|
||||
class PortForwardRoute extends LensApi {
|
||||
|
||||
public async routePortForward(request: LensApiRequest) {
|
||||
const { params, response, cluster} = request
|
||||
const { namespace, port, resourceType, resourceName } = params
|
||||
const { params, response, cluster} = request;
|
||||
const { namespace, port, resourceType, resourceName } = params;
|
||||
|
||||
let portForward = PortForward.getPortforward({
|
||||
clusterId: cluster.id, kind: resourceType, name: resourceName,
|
||||
namespace: namespace, port: port
|
||||
})
|
||||
});
|
||||
if (!portForward) {
|
||||
logger.info(`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`)
|
||||
logger.info(`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`);
|
||||
portForward = new PortForward({
|
||||
clusterId: cluster.id,
|
||||
kind: resourceType,
|
||||
@@ -89,20 +89,20 @@ class PortForwardRoute extends LensApi {
|
||||
name: resourceName,
|
||||
port: port,
|
||||
kubeConfig: cluster.getProxyKubeconfigPath()
|
||||
})
|
||||
const started = await portForward.start()
|
||||
});
|
||||
const started = await portForward.start();
|
||||
if (!started) {
|
||||
this.respondJson(response, {
|
||||
message: "Failed to open port-forward"
|
||||
}, 400)
|
||||
return
|
||||
}, 400);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
portForward.open()
|
||||
portForward.open();
|
||||
|
||||
this.respondJson(response, {})
|
||||
this.respondJson(response, {});
|
||||
}
|
||||
}
|
||||
|
||||
export const portForwardRoute = new PortForwardRoute()
|
||||
export const portForwardRoute = new PortForwardRoute();
|
||||
Reference in new issue
Block a user