1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/helm/helm-service/get-helm-release.injectable.ts
Janne Savolainen 22216f3d45 Fix opening of release details when release contains resources that do not have namespaces at all
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-09-06 11:10:25 -04:00

62 lines
1.7 KiB
TypeScript

/**
* 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 { Cluster } from "../../../common/cluster/cluster";
import loggerInjectable from "../../../common/logger.injectable";
import { isObject, json } from "../../../common/utils";
import { execHelm } from "../exec";
import getHelmReleaseResourcesInjectable from "./get-helm-release-resources/get-helm-release-resources.injectable";
const getHelmReleaseInjectable = getInjectable({
id: "get-helm-release",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const getHelmReleaseResources = di.inject(getHelmReleaseResourcesInjectable);
return async (cluster: Cluster, releaseName: string, namespace: string) => {
const kubeconfigPath = await cluster.getProxyKubeconfigPath();
const kubectl = await cluster.ensureKubectl();
const kubectlPath = await kubectl.getPath();
logger.debug("Fetch release");
const args = [
"status",
releaseName,
"--namespace",
namespace,
"--kubeconfig",
kubeconfigPath,
"--output",
"json",
];
const release = json.parse(
await execHelm(args, {
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
}),
);
if (!isObject(release) || Array.isArray(release)) {
return undefined;
}
release.resources = await getHelmReleaseResources(
releaseName,
namespace,
kubeconfigPath,
kubectlPath,
);
return release;
};
},
causesSideEffects: true,
});
export default getHelmReleaseInjectable;