1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make getHelmReleaseValues injectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-12-22 13:02:54 -05:00
parent 468ca34495
commit 52c93f3a29
5 changed files with 64 additions and 61 deletions

View File

@ -58,7 +58,6 @@ import getHelmChartVersionsInjectable from "./helm/helm-service/get-helm-chart-v
import getHelmChartValuesInjectable from "./helm/helm-service/get-helm-chart-values.injectable";
import listHelmChartsInjectable from "./helm/helm-service/list-helm-charts.injectable";
import getHelmReleaseHistoryInjectable from "./helm/helm-service/get-helm-release-history.injectable";
import getHelmReleaseValuesInjectable from "./helm/helm-service/get-helm-release-values.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 { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
@ -137,7 +136,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
getHelmChartValuesInjectable,
listHelmChartsInjectable,
getHelmReleaseHistoryInjectable,
getHelmReleaseValuesInjectable,
rollbackHelmReleaseInjectable,
writeJsonFileInjectable,
readJsonFileInjectable,

View File

@ -0,0 +1,49 @@
/**
* 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";
export interface GetHelmReleaseValuesData {
name: string;
namespace: string;
all?: boolean;
}
export type GetHelmReleaseValues = (kubeconfigPath: string, data: GetHelmReleaseValuesData) => Promise<string>;
const getHelmReleaseValuesInjectable = getInjectable({
id: "get-helm-release-values",
instantiate: (di): GetHelmReleaseValues => {
const execHelm = di.inject(execHelmInjectable);
return async (kubeconfigPath, { name, namespace, all = false }) => {
const args = [
"get",
"values",
name,
];
if (all) {
args.push("--all");
}
args.push(
"--output", "yaml",
"--namespace", namespace,
"--kubeconfig", kubeconfigPath,
);
const result = await execHelm(args);
if (result.callWasSuccessful) {
return result.response;
}
throw result.error;
};
},
});
export default getHelmReleaseValuesInjectable;

View File

@ -10,37 +10,6 @@ import execHelmInjectable from "./exec-helm/exec-helm.injectable";
const execHelm = asLegacyGlobalFunctionForExtensionApi(execHelmInjectable);
interface GetValuesOptions {
namespace: string;
all?: boolean;
kubeconfigPath: string;
}
export async function getValues(name: string, { namespace, all = false, kubeconfigPath }: GetValuesOptions): Promise<string> {
const args = [
"get",
"values",
name,
];
if (all) {
args.push("--all");
}
args.push(
"--output", "yaml",
"--namespace", namespace,
"--kubeconfig", kubeconfigPath,
);
const result = await execHelm(args);
if (result.callWasSuccessful) {
return result.response;
}
throw result.error;
}
export async function getHistory(name: string, namespace: string, kubeconfigPath: string): Promise<JsonValue> {
const result = await execHelm([

View File

@ -3,39 +3,26 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getValues } from "../helm-release-manager";
import loggerInjectable from "../../../common/logger.injectable";
import type { Cluster } from "../../../common/cluster/cluster";
import type { GetHelmReleaseValuesData } from "../get-helm-release-values.injectable";
import getHelmReleaseValuesInjectable from "../get-helm-release-values.injectable";
interface GetReleaseValuesArgs {
cluster: Cluster;
namespace: string;
all: boolean;
}
const getHelmReleaseValuesInjectable = getInjectable({
id: "get-helm-release-values",
const getClusterHelmReleaseValuesInjectable = getInjectable({
id: "get-cluster-helm-release-values",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const getHelmReleaseValues = di.inject(getHelmReleaseValuesInjectable);
return async (
releaseName: string,
{ cluster, namespace, all }: GetReleaseValuesArgs,
) => {
return async (cluster: Cluster, data: GetHelmReleaseValuesData) => {
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
logger.debug("Fetch release values");
logger.debug(`[CLUSTER]: getting helm release values`, data);
return getValues(releaseName, {
namespace,
all,
kubeconfigPath: pathToKubeconfig,
});
return getHelmReleaseValues(pathToKubeconfig, data);
};
},
causesSideEffects: true,
});
export default getHelmReleaseValuesInjectable;
export default getClusterHelmReleaseValuesInjectable;

View File

@ -7,20 +7,20 @@ import { getRouteInjectable } from "../../../router/router.injectable";
import { getBoolean } from "../../../utils/parse-query";
import { contentTypes } from "../../../router/router-content-types";
import { clusterRoute } from "../../../router/route";
import getHelmReleaseValuesInjectable from "../../../helm/helm-service/get-helm-release-values.injectable";
import getClusterHelmReleaseValuesInjectable from "../../../helm/helm-service/get-helm-release-values.injectable";
const getReleaseRouteValuesInjectable = getRouteInjectable({
id: "get-release-values-route",
instantiate: (di) => {
const getHelmReleaseValues = di.inject(getHelmReleaseValuesInjectable);
const getClusterHelmReleaseValues = di.inject(getClusterHelmReleaseValuesInjectable);
return clusterRoute({
method: "get",
path: `${apiPrefix}/v2/releases/{namespace}/{release}/values`,
})(async ({ cluster, params: { namespace, release }, query }) => ({
response: await getHelmReleaseValues(release, {
cluster,
path: `${apiPrefix}/v2/releases/{namespace}/{name}/values`,
})(async ({ cluster, params: { namespace, name }, query }) => ({
response: await getClusterHelmReleaseValues(cluster, {
name,
namespace,
all: getBoolean(query, "all"),
}),