Consolidate downloading binaries into one script (#4942)

* Consolidate downloading binaries into one script

- Upgrade lens-k8s-proxy to 0.1.5 which allows us to remove the trailing
  slash in KubeAuthProxy

- Consolidate nromalizing arch and os strings

- Remove LensBinary as HelmCli is not just a raw object since it is
  always bundled

- Introduce OnceCell and use it for the binary paths

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fully remove helmCli, move associated variable to vars

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix helm downloading on windows

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Don't download binaries for unsupported windows

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Arch specific paths

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix downloading helm on windows

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* rename once-cell file to lazy-initialized

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-03-09 17:51:51 -05:00
1 parent dd5dfb393d
commit a19f094a0d
23 files changed
+472 -641

No files matched your search

@@ -3,24 +3,24 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { KubeAuthProxy } from "./kube-auth-proxy";
import { KubeAuthProxy, KubeAuthProxyDependencies } from "./kube-auth-proxy";
import type { Cluster } from "../../common/cluster/cluster";
import path from "path";
import { isDevelopment, isWindows } from "../../common/vars";
import { getBinaryName } from "../../common/vars";
import directoryForBundledBinariesInjectable from "../../common/app-paths/directory-for-bundled-binaries/directory-for-bundled-binaries.injectable";
const createKubeAuthProxyInjectable = getInjectable({
id: "create-kube-auth-proxy",
instantiate: (di) => {
const binaryName = isWindows ? "lens-k8s-proxy.exe" : "lens-k8s-proxy";
const proxyPath = isDevelopment ? path.join("client", process.platform, process.arch) : process.arch;
const dependencies = {
proxyBinPath: path.join(di.inject(directoryForBundledBinariesInjectable), proxyPath, binaryName),
const binaryName = getBinaryName("lens-k8s-proxy");
const dependencies: KubeAuthProxyDependencies = {
proxyBinPath: path.join(di.inject(directoryForBundledBinariesInjectable), binaryName),
};
return (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) =>
new KubeAuthProxy(dependencies, cluster, environmentVariables);
return (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) => (
new KubeAuthProxy(dependencies, cluster, environmentVariables)
);
},
});
+4 -4
View File
@@ -13,7 +13,7 @@ import { makeObservable, observable, when } from "mobx";
const startingServeRegex = /starting to serve on (?<address>.+)/i;
interface Dependencies {
export interface KubeAuthProxyDependencies {
proxyBinPath: string;
}
@@ -28,7 +28,7 @@ export class KubeAuthProxy {
protected proxyProcess?: ChildProcess;
@observable protected ready = false;
constructor(private dependencies: Dependencies, protected readonly cluster: Cluster, protected readonly env: NodeJS.ProcessEnv) {
constructor(private dependencies: KubeAuthProxyDependencies, protected readonly cluster: Cluster, protected readonly env: NodeJS.ProcessEnv) {
makeObservable(this);
}
@@ -42,8 +42,8 @@ export class KubeAuthProxy {
}
const proxyBin = this.dependencies.proxyBinPath;
this.proxyProcess = spawn(proxyBin, [], {
this.proxyProcess = spawn(proxyBin, [], {
env: {
...this.env,
KUBECONFIG: this.cluster.kubeConfigPath,