Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: select namespace for dry-run config deploy #4168

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/components/organisms/ActionsPane/ActionsPaneHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useCallback, useMemo} from 'react';
import {useCallback, useMemo, useState} from 'react';

import {Button, Dropdown, Modal, Tooltip} from 'antd';
import {Button, Dropdown, Tooltip} from 'antd';

import {LeftOutlined, RightOutlined} from '@ant-design/icons';

Expand All @@ -21,6 +21,7 @@ import {runPreviewConfiguration} from '@redux/thunks/runPreviewConfiguration';
import {selectFromHistory} from '@redux/thunks/selectFromHistory';

import {TitleBarWrapper} from '@components/atoms';
import {HelmChartModalConfirmWithNamespaceSelect} from '@components/molecules';

import {useRefSelector} from '@utils/hooks';

Expand Down Expand Up @@ -50,6 +51,8 @@ const ActionsPaneHeader: React.FC<IProps> = props => {
const selectedHelmConfig = useAppSelector(selectedHelmConfigSelector);
const selectedImage = useAppSelector(selectedImageSelector);

const [isHelmChartApplyModalVisible, setIsHelmChartApplyModalVisible] = useState(false);

const onClickEditPreviewConfiguration = useCallback(() => {
if (!selectedHelmConfig) {
return;
Expand All @@ -74,18 +77,23 @@ const ActionsPaneHeader: React.FC<IProps> = props => {
dispatch(startPreview({type: 'helm-config', configId: selectedHelmConfig.id}));
}, [dispatch, selectedHelmConfig]);

const onClickInstallPreviewConfiguration = useCallback(() => {
Modal.confirm({
title: 'Install Helm Chart',
content: `Are you sure you want to install the ${selectedHelmConfig?.name} configuration to the cluster?`,
onOk: () => {
if (!selectedHelmConfig) {
return;
}
dispatch(runPreviewConfiguration({helmConfigId: selectedHelmConfig.id, performDeploy: true}));
},
});
}, [dispatch, selectedHelmConfig]);
const onConfirmInstallPreviewConfiguration = useCallback(
(selectedNamespace?: string, shouldCreateNamespace?: boolean) => {
if (!selectedHelmConfig) {
return;
}
dispatch(
runPreviewConfiguration({
helmConfigId: selectedHelmConfig.id,
performDeploy: true,
selectedNamespace,
shouldCreateNamespace,
})
);
setIsHelmChartApplyModalVisible(false);
},
[dispatch, selectedHelmConfig]
);

const onClickLeftArrow = useCallback(() => {
dispatch(selectFromHistory('left'));
Expand Down Expand Up @@ -135,6 +143,14 @@ const ActionsPaneHeader: React.FC<IProps> = props => {
if (selectedHelmConfig) {
return (
<TitleBarWrapper>
<HelmChartModalConfirmWithNamespaceSelect
isVisible={isHelmChartApplyModalVisible}
title="Install Helm Chart using Configuration"
onOk={onConfirmInstallPreviewConfiguration}
onCancel={() => {
setIsHelmChartApplyModalVisible(false);
}}
/>
<TitleBar
title="Helm Command"
type="secondary"
Expand All @@ -145,7 +161,7 @@ const ActionsPaneHeader: React.FC<IProps> = props => {
title={InstallPreviewConfigurationTooltip}
placement="bottomLeft"
>
<Button type="primary" size="small" ghost onClick={onClickInstallPreviewConfiguration}>
<Button type="primary" size="small" ghost onClick={() => setIsHelmChartApplyModalVisible(true)}>
Install
</Button>
</Tooltip>
Expand Down
15 changes: 14 additions & 1 deletion src/redux/thunks/runPreviewConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ export const runPreviewConfiguration = createAsyncThunk<
{
helmConfigId: string;
performDeploy?: boolean;
selectedNamespace?: string;
shouldCreateNamespace?: boolean;
},
{
dispatch: AppDispatch;
state: RootState;
}
>('main/runPreviewConfiguration', async ({helmConfigId, performDeploy}, thunkAPI) => {
>('main/runPreviewConfiguration', async (props, thunkAPI) => {
const {helmConfigId, performDeploy, selectedNamespace, shouldCreateNamespace} = props;
const startTime = new Date().getTime();
const configState = thunkAPI.getState().config;
const mainState = thunkAPI.getState().main;
Expand Down Expand Up @@ -133,6 +136,16 @@ export const runPreviewConfiguration = createAsyncThunk<
env: {KUBECONFIG: kubeconfig.path},
};

if (selectedNamespace) {
if (!commandOptions.args.some(arg => arg.includes('--namespace'))) {
commandOptions.args.push(...['--namespace', selectedNamespace]);
}

if (shouldCreateNamespace && !commandOptions.args.some(arg => arg.includes('--create-namespace'))) {
commandOptions.args.push('--create-namespace');
}
}

const result = await runCommandInMainThread(commandOptions);

if (result.error || result.stderr) {
Expand Down