mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
replace kubectl-proxy with lens-k8s-proxy
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
12a6bd8512
commit
c8ac776d25
5 files changed
+140
-25
No files matched your search
@@ -4,12 +4,17 @@
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import path from "path";
|
||||
import { isDevelopment, contextDir } from "../../vars";
|
||||
import directoryForUserDataInjectable from "../directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
const directoryForBinariesInjectable = getInjectable({
|
||||
instantiate: (di) =>
|
||||
path.join(di.inject(directoryForUserDataInjectable), "binaries"),
|
||||
instantiate: (di) => {
|
||||
if (isDevelopment) {
|
||||
return path.join(contextDir, "binaries");
|
||||
}
|
||||
|
||||
return path.join(di.inject(directoryForUserDataInjectable), "binaries");
|
||||
},
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { KubeAuthProxy } from "./kube-auth-proxy";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import bundledKubectlInjectable from "../kubectl/bundled-kubectl.injectable";
|
||||
import directoryForBinariesInjectable from "../../common/app-paths/directory-for-binaries/directory-for-binaries.injectable";
|
||||
import path from "path";
|
||||
import { isDevelopment, isWindows } from "../../common/vars";
|
||||
|
||||
const createKubeAuthProxyInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const bundledKubectl = di.inject(bundledKubectlInjectable);
|
||||
|
||||
const binaryName = isWindows ? "lens-k8s-proxy.exe" : "lens-k8s-proxy";
|
||||
const proxyPath = isDevelopment ? path.join("client", process.platform, process.arch) : process.arch;
|
||||
const dependencies = {
|
||||
getProxyBinPath: bundledKubectl.getPath,
|
||||
proxyBinPath: path.join(di.inject(directoryForBinariesInjectable), proxyPath, binaryName),
|
||||
};
|
||||
|
||||
return (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) =>
|
||||
|
||||
@@ -15,11 +15,11 @@ import { makeObservable, observable, when } from "mobx";
|
||||
const startingServeRegex = /^starting to serve on (?<address>.+)/i;
|
||||
|
||||
interface Dependencies {
|
||||
getProxyBinPath: () => Promise<string>;
|
||||
proxyBinPath: string;
|
||||
}
|
||||
|
||||
export class KubeAuthProxy {
|
||||
public readonly apiPrefix = `/${randomBytes(8).toString("hex")}`;
|
||||
public readonly apiPrefix = `/${randomBytes(8).toString("hex")}/`;
|
||||
|
||||
public get port(): number {
|
||||
return this._port;
|
||||
@@ -45,23 +45,15 @@ export class KubeAuthProxy {
|
||||
return this.whenReady;
|
||||
}
|
||||
|
||||
const proxyBin = await this.dependencies.getProxyBinPath();
|
||||
const args = [
|
||||
"proxy",
|
||||
"-p", "0",
|
||||
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
|
||||
"--context", `${this.cluster.contextName}`,
|
||||
"--accept-hosts", this.acceptHosts,
|
||||
"--reject-paths", "^[^/]",
|
||||
"--api-prefix", this.apiPrefix,
|
||||
];
|
||||
|
||||
if (process.env.DEBUG_PROXY === "true") {
|
||||
args.push("-v", "9");
|
||||
}
|
||||
logger.debug(`spawning kubectl proxy with args: ${args}`);
|
||||
|
||||
this.proxyProcess = spawn(proxyBin, args, { env: this.env });
|
||||
const proxyBin = this.dependencies.proxyBinPath;
|
||||
|
||||
this.proxyProcess = spawn(proxyBin, [], {
|
||||
env: {
|
||||
...this.env,
|
||||
KUBECONFIG: this.cluster.kubeConfigPath,
|
||||
API_PREFIX: this.apiPrefix,
|
||||
},
|
||||
});
|
||||
this.proxyProcess.on("error", (error) => {
|
||||
this.cluster.broadcastConnectUpdate(error.message, true);
|
||||
this.exit();
|
||||
|
||||
Reference in new issue
Block a user