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

Increase buffer size for execHelm

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-09-08 08:40:37 -04:00
parent 94e83cd110
commit 129eb3283e
8 changed files with 29 additions and 21 deletions

View File

@ -3,20 +3,23 @@
* 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 type { ExecFileOptions } from "child_process";
import { execFile } from "child_process"; import { execFile } from "child_process";
import { promisify } from "util"; import { promisify } from "util";
export type ExecFile = (filePath: string, args: string[]) => Promise<string>; export type ExecFile = (filePath: string, args: string[], options: ExecFileOptions) => Promise<string>;
const execFileInjectable = getInjectable({ const execFileInjectable = getInjectable({
id: "exec-file", id: "exec-file",
instantiate: (): ExecFile => async (filePath, args) => { instantiate: (): ExecFile => {
const asyncExecFile = promisify(execFile); const asyncExecFile = promisify(execFile);
const result = await asyncExecFile(filePath, args); return async (filePath, args, options) => {
const result = await asyncExecFile(filePath, args, options);
return result.stdout; return result.stdout;
};
}, },
causesSideEffects: true, causesSideEffects: true,

View File

@ -8,7 +8,7 @@ import helmBinaryPathInjectable from "../helm-binary-path.injectable";
import type { AsyncResult } from "../../../common/utils/async-result"; import type { AsyncResult } from "../../../common/utils/async-result";
import { getErrorMessage } from "../../../common/utils/get-error-message"; import { getErrorMessage } from "../../../common/utils/get-error-message";
export type ExecHelm = (...args: string[]) => Promise<AsyncResult<string>>; export type ExecHelm = (args: string[]) => Promise<AsyncResult<string>>;
const execHelmInjectable = getInjectable({ const execHelmInjectable = getInjectable({
id: "exec-helm", id: "exec-helm",
@ -17,9 +17,11 @@ const execHelmInjectable = getInjectable({
const execFile = di.inject(execFileInjectable); const execFile = di.inject(execFileInjectable);
const helmBinaryPath = di.inject(helmBinaryPathInjectable); const helmBinaryPath = di.inject(helmBinaryPathInjectable);
return async (...args) => { return async (args) => {
try { try {
const response = await execFile(helmBinaryPath, args); const response = await execFile(helmBinaryPath, args, {
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
});
return { callWasSuccessful: true, response }; return { callWasSuccessful: true, response };
} catch (error) { } catch (error) {

View File

@ -18,7 +18,7 @@ const getHelmEnvInjectable = getInjectable({
const execHelm = di.inject(execHelmInjectable); const execHelm = di.inject(execHelmInjectable);
return async (): Promise<AsyncResult<HelmEnv>> => { return async (): Promise<AsyncResult<HelmEnv>> => {
const result = await execHelm("env"); const result = await execHelm(["env"]);
if (!result.callWasSuccessful) { if (!result.callWasSuccessful) {
return { callWasSuccessful: false, error: result.error }; return { callWasSuccessful: false, error: result.error };

View File

@ -19,7 +19,7 @@ const callForHelmManifestInjectable = getInjectable({
namespace: string, namespace: string,
kubeconfigPath: string, kubeconfigPath: string,
): Promise<AsyncResult<KubeJsonApiData[]>> => { ): Promise<AsyncResult<KubeJsonApiData[]>> => {
const result = await execHelm( const result = await execHelm([
"get", "get",
"manifest", "manifest",
name, name,
@ -27,7 +27,7 @@ const callForHelmManifestInjectable = getInjectable({
namespace, namespace,
"--kubeconfig", "--kubeconfig",
kubeconfigPath, kubeconfigPath,
); ]);
if (!result.callWasSuccessful) { if (!result.callWasSuccessful) {
return { callWasSuccessful: false, error: result.error }; return { callWasSuccessful: false, error: result.error };

View File

@ -6,7 +6,7 @@ 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 { isObject, json } from "../../../common/utils"; import { isObject, json } from "../../../common/utils";
import { execHelm } from "../exec"; import execHelmInjectable from "../exec-helm/exec-helm.injectable";
import getHelmReleaseResourcesInjectable from "./get-helm-release-resources/get-helm-release-resources.injectable"; import getHelmReleaseResourcesInjectable from "./get-helm-release-resources/get-helm-release-resources.injectable";
const getHelmReleaseInjectable = getInjectable({ const getHelmReleaseInjectable = getInjectable({
@ -14,6 +14,7 @@ const getHelmReleaseInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const execHelm = di.inject(execHelmInjectable);
const getHelmReleaseResources = di.inject(getHelmReleaseResourcesInjectable); const getHelmReleaseResources = di.inject(getHelmReleaseResourcesInjectable);
return async (cluster: Cluster, releaseName: string, namespace: string) => { return async (cluster: Cluster, releaseName: string, namespace: string) => {
@ -34,11 +35,13 @@ const getHelmReleaseInjectable = getInjectable({
"json", "json",
]; ];
const release = json.parse( const result = await execHelm(args);
await execHelm(args, {
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB if (!result.callWasSuccessful) {
}), return undefined;
); }
const release = json.parse(result.response);
if (!isObject(release) || Array.isArray(release)) { if (!isObject(release) || Array.isArray(release)) {
return undefined; return undefined;

View File

@ -54,7 +54,7 @@ const addHelmRepositoryInjectable = getInjectable({
args.push("--cert-file", certFile); args.push("--cert-file", certFile);
} }
return await execHelm(...args); return await execHelm(args);
}; };
}, },
}); });

View File

@ -75,7 +75,7 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
}; };
} }
const updateResult = await execHelm("repo", "update"); const updateResult = await execHelm(["repo", "update"]);
if (!updateResult.callWasSuccessful) { if (!updateResult.callWasSuccessful) {
if (!updateResult.error.includes(internalHelmErrorForNoRepositoriesFound)) { if (!updateResult.error.includes(internalHelmErrorForNoRepositoriesFound)) {
@ -84,7 +84,7 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
error: `Error updating Helm repositories: ${updateResult.error}`, error: `Error updating Helm repositories: ${updateResult.error}`,
}; };
} }
const resultOfAddingDefaultRepository = await execHelm("repo", "add", "bitnami", "https://charts.bitnami.com/bitnami"); const resultOfAddingDefaultRepository = await execHelm(["repo", "add", "bitnami", "https://charts.bitnami.com/bitnami"]);
if (!resultOfAddingDefaultRepository.callWasSuccessful) { if (!resultOfAddingDefaultRepository.callWasSuccessful) {
return { return {

View File

@ -17,11 +17,11 @@ const removeHelmRepositoryInjectable = getInjectable({
return async (repo: HelmRepo) => { return async (repo: HelmRepo) => {
logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`); logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`);
return execHelm( return execHelm([
"repo", "repo",
"remove", "remove",
repo.name, repo.name,
); ]);
}; };
}, },
}); });