Skip to content

Commit

Permalink
fix: use runCommandInMainThread to run preview configurations + elect…
Browse files Browse the repository at this point in the history
…ron update
  • Loading branch information
olensmar committed Mar 8, 2022
1 parent 372a401 commit d3ed55e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"craco-alias": "3.0.1",
"craco-less": "1.20.0",
"cross-env": "7.0.3",
"electron": "17.1.0",
"electron": "17.1.1",
"electron-builder": "23.0.0-alpha.3",
"electron-notarize": "1.1.1",
"electron-reload": "2.0.0-alpha.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PreviwConfigurationDetails: React.FC = () => {

const builtCommand = useMemo(() => {
if (!previewConfiguration || !helmChart) {
return '';
return [''];
}
return buildHelmCommand(
helmChart,
Expand Down Expand Up @@ -72,7 +72,7 @@ const PreviwConfigurationDetails: React.FC = () => {
</Breadcrumb>
)}
<Text code copyable>
{builtCommand}
{builtCommand.join(' ')}
</Text>
</Container>
);
Expand Down
17 changes: 8 additions & 9 deletions src/redux/thunks/runPreviewConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {createAsyncThunk} from '@reduxjs/toolkit';

import fs from 'fs';
import log from 'loglevel';
import path from 'path';

import {ROOT_FILE_ENTRY} from '@constants/constants';
Expand All @@ -13,7 +12,8 @@ import {RootState} from '@models/rootstate';
import {SetPreviewDataPayload} from '@redux/reducers/main';
import {createPreviewResult, createRejectionWithAlert} from '@redux/thunks/utils';

import {buildHelmCommand, runHelm} from '@utils/helm';
import {CommandOptions, runCommandInMainThread} from '@utils/command';
import {buildHelmCommand} from '@utils/helm';

/**
* Thunk to preview a Helm Chart
Expand Down Expand Up @@ -89,9 +89,7 @@ export const runPreviewConfiguration = createAsyncThunk<
);
}

log.info(`Running the following Preview Configuration: ${previewConfiguration.id}`);

const helmCommand = buildHelmCommand(
const args = buildHelmCommand(
chart,
previewConfiguration.orderedValuesFilePaths,
previewConfiguration.command,
Expand All @@ -100,12 +98,13 @@ export const runPreviewConfiguration = createAsyncThunk<
currentContext
);

const args = {
helmCommand,
kubeconfig,
const commandOptions: CommandOptions = {
cmd: 'helm',
args: args.splice(1),
env: {KUBECONFIG: kubeconfig},
};

const result = await runHelm(args);
const result = await runCommandInMainThread(commandOptions);

if (result.error) {
return createRejectionWithAlert(thunkAPI, 'Helm Error', result.error);
Expand Down
18 changes: 2 additions & 16 deletions src/utils/helm.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import {ipcRenderer} from 'electron';

import path from 'path';

import {HelmChart} from '@models/helm';

/**
* Invokes Helm in main thread
*/
export function runHelm(cmd: any): any {
return new Promise(resolve => {
ipcRenderer.once('helm-result', (event, arg) => {
resolve(arg);
});
ipcRenderer.send('run-helm', cmd);
});
}

export function buildHelmCommand(
helmChart: HelmChart,
valuesFilePaths: string[],
command: 'template' | 'install',
options: Record<string, string | null>,
rootFolderPath: string,
clusterContext?: string
): string {
): string[] {
const chartFolderPath = path.join(rootFolderPath, path.dirname(helmChart.filePath));

const args = [
Expand All @@ -44,5 +30,5 @@ export function buildHelmCommand(
args.push('--dry-run');
}

return args.join(' ');
return args;
}

0 comments on commit d3ed55e

Please sign in to comment.