mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make getHelmReleaseHistory injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
52c93f3a29
commit
23a7e79b35
@ -57,7 +57,6 @@ import normalizedPlatformArchitectureInjectable from "../common/vars/normalized-
|
||||
import getHelmChartVersionsInjectable from "./helm/helm-service/get-helm-chart-versions.injectable";
|
||||
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 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";
|
||||
@ -135,7 +134,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
getHelmChartVersionsInjectable,
|
||||
getHelmChartValuesInjectable,
|
||||
listHelmChartsInjectable,
|
||||
getHelmReleaseHistoryInjectable,
|
||||
rollbackHelmReleaseInjectable,
|
||||
writeJsonFileInjectable,
|
||||
readJsonFileInjectable,
|
||||
|
||||
39
src/main/helm/get-helm-release-history.injectable.ts
Normal file
39
src/main/helm/get-helm-release-history.injectable.ts
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 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 type { HelmReleaseRevision } from "../../common/k8s-api/endpoints/helm-releases.api/request-history.injectable";
|
||||
import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
||||
|
||||
export interface GetHelmReleaseHistoryData {
|
||||
name: string;
|
||||
namespace: string;
|
||||
}
|
||||
|
||||
export type GetHelmReleaseHistory = (kubeconfigPath: string, data: GetHelmReleaseHistoryData) => Promise<HelmReleaseRevision[]>;
|
||||
|
||||
const getHelmReleaseHistoryInjectable = getInjectable({
|
||||
id: "get-helm-release-history",
|
||||
instantiate: (di): GetHelmReleaseHistory => {
|
||||
const execHelm = di.inject(execHelmInjectable);
|
||||
|
||||
return async (kubeconfigPath, { name, namespace }) => {
|
||||
const result = await execHelm([
|
||||
"history",
|
||||
name,
|
||||
"--output", "json",
|
||||
"--namespace", namespace,
|
||||
"--kubeconfig", kubeconfigPath,
|
||||
]);
|
||||
|
||||
if (result.callWasSuccessful) {
|
||||
return JSON.parse(result.response);
|
||||
}
|
||||
|
||||
throw result.error;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default getHelmReleaseHistoryInjectable;
|
||||
@ -3,30 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { JsonValue } from "type-fest";
|
||||
import { json } from "../../common/utils";
|
||||
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";
|
||||
|
||||
const execHelm = asLegacyGlobalFunctionForExtensionApi(execHelmInjectable);
|
||||
|
||||
|
||||
export async function getHistory(name: string, namespace: string, kubeconfigPath: string): Promise<JsonValue> {
|
||||
const result = await execHelm([
|
||||
"history",
|
||||
name,
|
||||
"--output", "json",
|
||||
"--namespace", namespace,
|
||||
"--kubeconfig", kubeconfigPath,
|
||||
]);
|
||||
|
||||
if (result.callWasSuccessful) {
|
||||
return json.parse(result.response);
|
||||
}
|
||||
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
export async function rollback(name: string, namespace: string, revision: number, kubeconfigPath: string): Promise<void> {
|
||||
const result = await execHelm([
|
||||
"rollback",
|
||||
|
||||
@ -4,25 +4,25 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import { getHistory } from "../helm-release-manager";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import type { GetHelmReleaseHistoryData } from "../get-helm-release-history.injectable";
|
||||
import getHelmReleaseHistoryInjectable from "../get-helm-release-history.injectable";
|
||||
|
||||
const getHelmReleaseHistoryInjectable = getInjectable({
|
||||
id: "get-helm-release-history",
|
||||
const getClusterHelmReleaseHistoryInjectable = getInjectable({
|
||||
id: "get-cluster-helm-release-history",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const getHelmReleaseHistory = di.inject(getHelmReleaseHistoryInjectable);
|
||||
|
||||
return async (cluster: Cluster, releaseName: string, namespace: string) => {
|
||||
return async (cluster: Cluster, data: GetHelmReleaseHistoryData) => {
|
||||
const proxyKubeconfig = await cluster.getProxyKubeconfigPath();
|
||||
|
||||
logger.debug("Fetch release history");
|
||||
logger.debug(`[CLUSTER]: Fetch release history for clusterId=${cluster.id}`, data);
|
||||
|
||||
return getHistory(releaseName, namespace, proxyKubeconfig);
|
||||
return getHelmReleaseHistory(proxyKubeconfig, data);
|
||||
};
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getHelmReleaseHistoryInjectable;
|
||||
export default getClusterHelmReleaseHistoryInjectable;
|
||||
|
||||
@ -5,23 +5,19 @@
|
||||
import { apiPrefix } from "../../../../common/vars";
|
||||
import { getRouteInjectable } from "../../../router/router.injectable";
|
||||
import { clusterRoute } from "../../../router/route";
|
||||
import getHelmReleaseHistoryInjectable from "../../../helm/helm-service/get-helm-release-history.injectable";
|
||||
import getClusterHelmReleaseHistoryInjectable from "../../../helm/helm-service/get-helm-release-history.injectable";
|
||||
|
||||
const getReleaseRouteHistoryInjectable = getRouteInjectable({
|
||||
id: "get-release-history-route",
|
||||
|
||||
instantiate: (di) => {
|
||||
const getHelmReleaseHistory = di.inject(getHelmReleaseHistoryInjectable);
|
||||
const getHelmReleaseHistory = di.inject(getClusterHelmReleaseHistoryInjectable);
|
||||
|
||||
return clusterRoute({
|
||||
method: "get",
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{release}/history`,
|
||||
path: `${apiPrefix}/v2/releases/{namespace}/{name}/history`,
|
||||
})(async ({ cluster, params }) => ({
|
||||
response: await getHelmReleaseHistory(
|
||||
cluster,
|
||||
params.release,
|
||||
params.namespace,
|
||||
),
|
||||
response: await getHelmReleaseHistory(cluster, params),
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user