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:
parent
468ca34495
commit
52c93f3a29
@ -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 getHelmChartValuesInjectable from "./helm/helm-service/get-helm-chart-values.injectable";
|
||||||
import listHelmChartsInjectable from "./helm/helm-service/list-helm-charts.injectable";
|
import listHelmChartsInjectable from "./helm/helm-service/list-helm-charts.injectable";
|
||||||
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 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";
|
||||||
@ -137,7 +136,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
|||||||
getHelmChartValuesInjectable,
|
getHelmChartValuesInjectable,
|
||||||
listHelmChartsInjectable,
|
listHelmChartsInjectable,
|
||||||
getHelmReleaseHistoryInjectable,
|
getHelmReleaseHistoryInjectable,
|
||||||
getHelmReleaseValuesInjectable,
|
|
||||||
rollbackHelmReleaseInjectable,
|
rollbackHelmReleaseInjectable,
|
||||||
writeJsonFileInjectable,
|
writeJsonFileInjectable,
|
||||||
readJsonFileInjectable,
|
readJsonFileInjectable,
|
||||||
|
|||||||
49
src/main/helm/get-helm-release-values.injectable.ts
Normal file
49
src/main/helm/get-helm-release-values.injectable.ts
Normal 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;
|
||||||
@ -10,37 +10,6 @@ import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
|||||||
|
|
||||||
const execHelm = asLegacyGlobalFunctionForExtensionApi(execHelmInjectable);
|
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> {
|
export async function getHistory(name: string, namespace: string, kubeconfigPath: string): Promise<JsonValue> {
|
||||||
const result = await execHelm([
|
const result = await execHelm([
|
||||||
|
|||||||
@ -3,39 +3,26 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { getValues } from "../helm-release-manager";
|
|
||||||
import loggerInjectable from "../../../common/logger.injectable";
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
import type { Cluster } from "../../../common/cluster/cluster";
|
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 {
|
const getClusterHelmReleaseValuesInjectable = getInjectable({
|
||||||
cluster: Cluster;
|
id: "get-cluster-helm-release-values",
|
||||||
namespace: string;
|
|
||||||
all: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getHelmReleaseValuesInjectable = getInjectable({
|
|
||||||
id: "get-helm-release-values",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const logger = di.inject(loggerInjectable);
|
const logger = di.inject(loggerInjectable);
|
||||||
|
const getHelmReleaseValues = di.inject(getHelmReleaseValuesInjectable);
|
||||||
|
|
||||||
return async (
|
return async (cluster: Cluster, data: GetHelmReleaseValuesData) => {
|
||||||
releaseName: string,
|
|
||||||
{ cluster, namespace, all }: GetReleaseValuesArgs,
|
|
||||||
) => {
|
|
||||||
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
||||||
|
|
||||||
logger.debug("Fetch release values");
|
logger.debug(`[CLUSTER]: getting helm release values`, data);
|
||||||
|
|
||||||
return getValues(releaseName, {
|
return getHelmReleaseValues(pathToKubeconfig, data);
|
||||||
namespace,
|
|
||||||
all,
|
|
||||||
kubeconfigPath: pathToKubeconfig,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default getHelmReleaseValuesInjectable;
|
export default getClusterHelmReleaseValuesInjectable;
|
||||||
|
|||||||
@ -7,20 +7,20 @@ import { getRouteInjectable } from "../../../router/router.injectable";
|
|||||||
import { getBoolean } from "../../../utils/parse-query";
|
import { getBoolean } from "../../../utils/parse-query";
|
||||||
import { contentTypes } from "../../../router/router-content-types";
|
import { contentTypes } from "../../../router/router-content-types";
|
||||||
import { clusterRoute } from "../../../router/route";
|
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({
|
const getReleaseRouteValuesInjectable = getRouteInjectable({
|
||||||
id: "get-release-values-route",
|
id: "get-release-values-route",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const getHelmReleaseValues = di.inject(getHelmReleaseValuesInjectable);
|
const getClusterHelmReleaseValues = di.inject(getClusterHelmReleaseValuesInjectable);
|
||||||
|
|
||||||
return clusterRoute({
|
return clusterRoute({
|
||||||
method: "get",
|
method: "get",
|
||||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}/values`,
|
path: `${apiPrefix}/v2/releases/{namespace}/{name}/values`,
|
||||||
})(async ({ cluster, params: { namespace, release }, query }) => ({
|
})(async ({ cluster, params: { namespace, name }, query }) => ({
|
||||||
response: await getHelmReleaseValues(release, {
|
response: await getClusterHelmReleaseValues(cluster, {
|
||||||
cluster,
|
name,
|
||||||
namespace,
|
namespace,
|
||||||
all: getBoolean(query, "all"),
|
all: getBoolean(query, "all"),
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user