mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup 'Cluster' to remove environment specific details (#6951)
- requestNamespaceListPermissions is infallable so no need to have the extra try/catch - Refactor isMetricHidden method away from Cluster - Refactor shouldShowResource out of Cluster - Refactor isInLocalKubeconfig out of Cluster - Remove depecrated and unused workspace from Cluster - Refactor out kubectl as a dependency of Cluster - Remove from cluster getter used only once - Split out ClusterConnection from Cluster - Also split out KubeAuthProxyServer from ContextHandler - Rename ContextHandler to PrometheusHandler - Cleanup onNetworkOffline/Online impls within ClusterManager - Remove annotations from ClusterConnection - Remove mobx annotations from Cluster - Rename loadConfigFromFileInjectable - Remove all uses of dead createClusterInjectionToken - Fix type errors related to broadcastConnectionUpdate Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
e6d6d1d8f7
commit
ad9bafe2a5
133 files changed
+2544
-1961
No files matched your search
@@ -2,33 +2,36 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import emitAppEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import removePathInjectable from "../../common/fs/remove.injectable";
|
||||
import execFileInjectable from "../../common/fs/exec-file.injectable";
|
||||
import writeFileInjectable from "../../common/fs/write-file.injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||
import type { ResourceApplierDependencies } from "./resource-applier";
|
||||
import { ResourceApplier } from "./resource-applier";
|
||||
import createKubectlInjectable from "../kubectl/create-kubectl.injectable";
|
||||
import kubeconfigManagerInjectable from "../kubeconfig-manager/kubeconfig-manager.injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
|
||||
export type CreateResourceApplier = (cluster: Cluster) => ResourceApplier;
|
||||
|
||||
const createResourceApplierInjectable = getInjectable({
|
||||
id: "create-resource-applier",
|
||||
instantiate: (di): CreateResourceApplier => {
|
||||
const deps: ResourceApplierDependencies = {
|
||||
const resourceApplierInjectable = getInjectable({
|
||||
id: "resource-applier",
|
||||
instantiate: (di, cluster) => new ResourceApplier(
|
||||
{
|
||||
deleteFile: di.inject(removePathInjectable),
|
||||
emitAppEvent: di.inject(emitAppEventInjectable),
|
||||
execFile: di.inject(execFileInjectable),
|
||||
joinPaths: di.inject(joinPathsInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
writeFile: di.inject(writeFileInjectable),
|
||||
};
|
||||
|
||||
return (cluster) => new ResourceApplier(deps, cluster);
|
||||
},
|
||||
createKubectl: di.inject(createKubectlInjectable),
|
||||
proxyKubeconfigManager: di.inject(kubeconfigManagerInjectable, cluster),
|
||||
},
|
||||
cluster,
|
||||
),
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, cluster: Cluster) => cluster.id,
|
||||
}),
|
||||
});
|
||||
|
||||
export default createResourceApplierInjectable;
|
||||
export default resourceApplierInjectable;
|
||||
@@ -15,6 +15,8 @@ import type { RemovePath } from "../../common/fs/remove.injectable";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { CreateKubectl } from "../kubectl/create-kubectl.injectable";
|
||||
import type { KubeconfigManager } from "../kubeconfig-manager/kubeconfig-manager";
|
||||
|
||||
export interface ResourceApplierDependencies {
|
||||
emitAppEvent: EmitAppEvent;
|
||||
@@ -22,11 +24,24 @@ export interface ResourceApplierDependencies {
|
||||
deleteFile: RemovePath;
|
||||
execFile: ExecFile;
|
||||
joinPaths: JoinPaths;
|
||||
createKubectl: CreateKubectl;
|
||||
readonly proxyKubeconfigManager: KubeconfigManager;
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
export class ResourceApplier {
|
||||
constructor(protected readonly dependencies: ResourceApplierDependencies, protected readonly cluster: Cluster) {}
|
||||
constructor(
|
||||
protected readonly dependencies: ResourceApplierDependencies,
|
||||
protected readonly cluster: Cluster,
|
||||
) {}
|
||||
|
||||
private async getKubectlPath() {
|
||||
const kubectl = this.dependencies.createKubectl(this.cluster.version.get());
|
||||
|
||||
await kubectl.ensureKubectl();
|
||||
|
||||
return kubectl.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch a kube resource's manifest, throwing any error that occurs.
|
||||
@@ -38,9 +53,8 @@ export class ResourceApplier {
|
||||
async patch(name: string, kind: string, patch: Patch, ns?: string): Promise<string> {
|
||||
this.dependencies.emitAppEvent({ name: "resource", action: "patch" });
|
||||
|
||||
const kubectl = await this.cluster.ensureKubectl();
|
||||
const kubectlPath = await kubectl.getPath();
|
||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||
const kubectlPath = await this.getKubectlPath();
|
||||
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
|
||||
const args = [
|
||||
"--kubeconfig", proxyKubeconfigPath,
|
||||
"patch",
|
||||
@@ -74,9 +88,8 @@ export class ResourceApplier {
|
||||
}
|
||||
|
||||
protected async kubectlApply(content: string): Promise<AsyncResult<string, string>> {
|
||||
const kubectl = await this.cluster.ensureKubectl();
|
||||
const kubectlPath = await kubectl.getPath();
|
||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||
const kubectlPath = await this.getKubectlPath();
|
||||
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
|
||||
const fileName = tempy.file({ name: "resource.yaml" });
|
||||
const args = [
|
||||
"apply",
|
||||
@@ -121,9 +134,8 @@ export class ResourceApplier {
|
||||
}
|
||||
|
||||
protected async kubectlCmdAll(subCmd: string, resources: string[], parentArgs: string[] = []): Promise<AsyncResult<string, string>> {
|
||||
const kubectl = await this.cluster.ensureKubectl();
|
||||
const kubectlPath = await kubectl.getPath();
|
||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||
const kubectlPath = await this.getKubectlPath();
|
||||
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
|
||||
const tmpDir = tempy.directory();
|
||||
|
||||
await Promise.all(resources.map((resource, index) => this.dependencies.writeFile(
|
||||
|
||||
Reference in new issue
Block a user