mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make listHelmReleases injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ad09d15385
commit
a449356e2a
@ -61,7 +61,6 @@ import deleteHelmReleaseInjectable from "./helm/helm-service/delete-helm-release
|
|||||||
import getHelmReleaseHistoryInjectable from "./helm/helm-service/get-helm-release-history.injectable";
|
import getHelmReleaseHistoryInjectable from "./helm/helm-service/get-helm-release-history.injectable";
|
||||||
import getHelmReleaseValuesInjectable from "./helm/helm-service/get-helm-release-values.injectable";
|
import getHelmReleaseValuesInjectable from "./helm/helm-service/get-helm-release-values.injectable";
|
||||||
import installHelmChartInjectable from "./helm/helm-service/install-helm-chart.injectable";
|
import installHelmChartInjectable from "./helm/helm-service/install-helm-chart.injectable";
|
||||||
import listHelmReleasesInjectable from "./helm/helm-service/list-helm-releases.injectable";
|
|
||||||
import rollbackHelmReleaseInjectable from "./helm/helm-service/rollback-helm-release.injectable";
|
import rollbackHelmReleaseInjectable from "./helm/helm-service/rollback-helm-release.injectable";
|
||||||
import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable";
|
import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable";
|
||||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||||
@ -143,7 +142,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
|||||||
getHelmReleaseHistoryInjectable,
|
getHelmReleaseHistoryInjectable,
|
||||||
getHelmReleaseValuesInjectable,
|
getHelmReleaseValuesInjectable,
|
||||||
installHelmChartInjectable,
|
installHelmChartInjectable,
|
||||||
listHelmReleasesInjectable,
|
|
||||||
rollbackHelmReleaseInjectable,
|
rollbackHelmReleaseInjectable,
|
||||||
writeJsonFileInjectable,
|
writeJsonFileInjectable,
|
||||||
readJsonFileInjectable,
|
readJsonFileInjectable,
|
||||||
|
|||||||
@ -6,45 +6,13 @@
|
|||||||
import tempy from "tempy";
|
import tempy from "tempy";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import * as yaml from "js-yaml";
|
import * as yaml from "js-yaml";
|
||||||
import { toCamelCase } from "../../common/utils/camelCase";
|
|
||||||
import type { JsonValue } from "type-fest";
|
import type { JsonValue } from "type-fest";
|
||||||
import { isObject, json } from "../../common/utils";
|
import { json } from "../../common/utils";
|
||||||
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||||
import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
||||||
|
|
||||||
const execHelm = asLegacyGlobalFunctionForExtensionApi(execHelmInjectable);
|
const execHelm = asLegacyGlobalFunctionForExtensionApi(execHelmInjectable);
|
||||||
|
|
||||||
export async function listReleases(pathToKubeconfig: string, namespace?: string): Promise<Record<string, any>[]> {
|
|
||||||
const args = [
|
|
||||||
"ls",
|
|
||||||
"--all",
|
|
||||||
"--output", "json",
|
|
||||||
];
|
|
||||||
|
|
||||||
if (namespace) {
|
|
||||||
args.push("-n", namespace);
|
|
||||||
} else {
|
|
||||||
args.push("--all-namespaces");
|
|
||||||
}
|
|
||||||
|
|
||||||
args.push("--kubeconfig", pathToKubeconfig);
|
|
||||||
|
|
||||||
const result = await execHelm(args);
|
|
||||||
|
|
||||||
if (!result.callWasSuccessful) {
|
|
||||||
throw result.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = json.parse(result.response);
|
|
||||||
|
|
||||||
if (!Array.isArray(output) || output.length == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.filter(isObject).map(toCamelCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export async function installChart(chart: string, values: JsonValue, name: string | undefined = "", namespace: string, version: string, kubeconfigPath: string) {
|
export async function installChart(chart: string, values: JsonValue, name: string | undefined = "", namespace: string, version: string, kubeconfigPath: string) {
|
||||||
const valuesFilePath = tempy.file({ name: "values.yaml" });
|
const valuesFilePath = tempy.file({ name: "values.yaml" });
|
||||||
|
|
||||||
|
|||||||
@ -5,24 +5,23 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { Cluster } from "../../../common/cluster/cluster";
|
import type { Cluster } from "../../../common/cluster/cluster";
|
||||||
import loggerInjectable from "../../../common/logger.injectable";
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
import { listReleases } from "../helm-release-manager";
|
import listHelmReleasesInjectable from "../list-helm-releases.injectable";
|
||||||
|
|
||||||
const listHelmReleasesInjectable = getInjectable({
|
const listClusterHelmReleasesInjectable = getInjectable({
|
||||||
id: "list-helm-releases",
|
id: "list-cluster-helm-releases",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const logger = di.inject(loggerInjectable);
|
const logger = di.inject(loggerInjectable);
|
||||||
|
const listHelmReleases = di.inject(listHelmReleasesInjectable);
|
||||||
|
|
||||||
return async (cluster: Cluster, namespace?: string) => {
|
return async (cluster: Cluster, namespace?: string) => {
|
||||||
const proxyKubeconfig = await cluster.getProxyKubeconfigPath();
|
const proxyKubeconfig = await cluster.getProxyKubeconfigPath();
|
||||||
|
|
||||||
logger.debug("list releases");
|
logger.debug(`[CLUSTER]: listing helm releases for clusterId=${cluster.id}`, { namespace });
|
||||||
|
|
||||||
return listReleases(proxyKubeconfig, namespace);
|
return listHelmReleases(proxyKubeconfig, namespace);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default listHelmReleasesInjectable;
|
export default listClusterHelmReleasesInjectable;
|
||||||
|
|||||||
48
src/main/helm/list-helm-releases.injectable.ts
Normal file
48
src/main/helm/list-helm-releases.injectable.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* 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 execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
||||||
|
import { isObject, json, toCamelCase } from "../../common/utils";
|
||||||
|
|
||||||
|
export type ListHelmReleases = (pathToKubeconfig: string, namespace?: string) => Promise<Record<string, any>[]>;
|
||||||
|
|
||||||
|
const listHelmReleasesInjectable = getInjectable({
|
||||||
|
id: "list-helm-releases",
|
||||||
|
instantiate: (di): ListHelmReleases => {
|
||||||
|
const execHelm = di.inject(execHelmInjectable);
|
||||||
|
|
||||||
|
return async (pathToKubeconfig, namespace) => {
|
||||||
|
const args = [
|
||||||
|
"ls",
|
||||||
|
"--all",
|
||||||
|
"--output", "json",
|
||||||
|
];
|
||||||
|
|
||||||
|
if (namespace) {
|
||||||
|
args.push("-n", namespace);
|
||||||
|
} else {
|
||||||
|
args.push("--all-namespaces");
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push("--kubeconfig", pathToKubeconfig);
|
||||||
|
|
||||||
|
const result = await execHelm(args);
|
||||||
|
|
||||||
|
if (!result.callWasSuccessful) {
|
||||||
|
throw result.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = json.parse(result.response);
|
||||||
|
|
||||||
|
if (!Array.isArray(output) || output.length == 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.filter(isObject).map(toCamelCase);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default listHelmReleasesInjectable;
|
||||||
@ -5,13 +5,13 @@
|
|||||||
import { apiPrefix } from "../../../../common/vars";
|
import { apiPrefix } from "../../../../common/vars";
|
||||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||||
import { clusterRoute } from "../../../router/route";
|
import { clusterRoute } from "../../../router/route";
|
||||||
import listHelmReleasesInjectable from "../../../helm/helm-service/list-helm-releases.injectable";
|
import listClusterHelmReleasesInjectable from "../../../helm/helm-service/list-helm-releases.injectable";
|
||||||
|
|
||||||
const listReleasesRouteInjectable = getRouteInjectable({
|
const listReleasesRouteInjectable = getRouteInjectable({
|
||||||
id: "list-releases-route",
|
id: "list-releases-route",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const listHelmReleases = di.inject(listHelmReleasesInjectable);
|
const listHelmReleases = di.inject(listClusterHelmReleasesInjectable);
|
||||||
|
|
||||||
return clusterRoute({
|
return clusterRoute({
|
||||||
method: "get",
|
method: "get",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user