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(ui): Show prompt when every resource requires pruning #16603

Merged
merged 6 commits into from
Dec 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './application-sync-options.scss';

export const REPLACE_WARNING = `The resources will be synced using 'kubectl replace/create' command that is a potentially destructive action and might cause resources recreation.`;
export const FORCE_WARNING = `The resources will be synced using '--force' that is a potentially destructive action and will immediately remove resources from the API and bypasses graceful deletion. Immediate deletion of some resources may result in inconsistency or data loss.`;
export const PRUNE_ALL_WARNING = `The resources will be synced using '--prune', and all resources are marked to be pruned. Only continue if you want to delete all of the Application's resources.`;

export interface ApplicationSyncOptionProps {
options: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {Consumer} from '../../../shared/context';
import * as models from '../../../shared/models';
import {services} from '../../../shared/services';
import {ApplicationRetryOptions} from '../application-retry-options/application-retry-options';
import {ApplicationManualSyncFlags, ApplicationSyncOptions, FORCE_WARNING, SyncFlags, REPLACE_WARNING} from '../application-sync-options/application-sync-options';
import {
ApplicationManualSyncFlags,
ApplicationSyncOptions,
FORCE_WARNING,
SyncFlags,
REPLACE_WARNING,
PRUNE_ALL_WARNING
} from '../application-sync-options/application-sync-options';
import {ComparisonStatusIcon, getAppDefaultSource, nodeKey} from '../utils';

import './application-sync-panel.scss';
Expand Down Expand Up @@ -57,9 +64,25 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
})}
onSubmit={async (params: any) => {
setPending(true);
let resources = appResources.filter((_, i) => params.resources[i]);
if (resources.length === appResources.length) {
resources = null;
let selectedResources = appResources.filter((_, i) => params.resources[i]);
const allResourcesAreSelected = selectedResources.length === appResources.length;
const syncFlags = {...params.syncFlags} as SyncFlags;

const allRequirePruning = !selectedResources.some(resource => !resource?.requiresPruning);
if (syncFlags.Prune && allRequirePruning && allResourcesAreSelected) {
const confirmed = await ctx.popup.confirm('Prune all resources?', () => (
<div>
<i className='fa fa-exclamation-triangle' style={{color: ARGO_WARNING_COLOR}} />
{PRUNE_ALL_WARNING} Are you sure you want to continue?
</div>
));
if (!confirmed) {
setPending(false);
return;
}
}
if (allResourcesAreSelected) {
selectedResources = null;
}
const replace = params.syncOptions?.findIndex((opt: string) => opt === 'Replace=true') > -1;
if (replace) {
Expand All @@ -74,7 +97,6 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
}
}

const syncFlags = {...params.syncFlags} as SyncFlags;
const force = syncFlags.Force || false;

if (syncFlags.ApplyOnly) {
Expand Down Expand Up @@ -102,7 +124,7 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
syncFlags.Prune || false,
syncFlags.DryRun || false,
syncStrategy,
resources,
selectedResources,
params.syncOptions,
params.retryStrategy
);
Expand Down
Loading