Skip to content

Commit

Permalink
feat: add prompting to confirm application resource deletion (argopro…
Browse files Browse the repository at this point in the history
…j#20611)

* Revert "fix(ui): Prevent versionId 0 Error on New Applications with No History (argoproj#20574)"

This reverts commit 33ecbbc.

* feat: add prompting to confirm app resource deletion

Signed-off-by: pashakostohrys <pavel@codefresh.io>

* Revert "Revert "fix(ui): Prevent versionId 0 Error on New Applications with No History (argoproj#20574)""

This reverts commit cecf8f4.

---------

Signed-off-by: pashakostohrys <pavel@codefresh.io>
  • Loading branch information
pasha-codefresh authored Oct 31, 2024
1 parent a7637cd commit d44d7ec
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions cmd/argocd/commands/app_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"text/tabwriter"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/utils"
"github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"

Expand Down Expand Up @@ -130,23 +131,32 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
errors.CheckError(err)
objectsToDelete, err := util.FilterResources(command.Flags().Changed("group"), resources.Items, group, kind, namespace, resourceName, all)
errors.CheckError(err)

promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled)

for i := range objectsToDelete {
obj := objectsToDelete[i]
gvk := obj.GroupVersionKind()
_, err = appIf.DeleteResource(ctx, &applicationpkg.ApplicationResourceDeleteRequest{
Name: &appName,
AppNamespace: &appNs,
Namespace: ptr.To(obj.GetNamespace()),
ResourceName: ptr.To(obj.GetName()),
Version: ptr.To(gvk.Version),
Group: ptr.To(gvk.Group),
Kind: ptr.To(gvk.Kind),
Force: &force,
Orphan: &orphan,
Project: ptr.To(project),
})
errors.CheckError(err)
log.Infof("Resource '%s' deleted", obj.GetName())

canDelete := promptUtil.Confirm(fmt.Sprintf("Are you sure you want to delete %s/%s %s/%s ? [y/n]", gvk.Group, gvk.Kind, obj.GetNamespace(), obj.GetName()))
if canDelete {
_, err = appIf.DeleteResource(ctx, &applicationpkg.ApplicationResourceDeleteRequest{
Name: &appName,
AppNamespace: &appNs,
Namespace: ptr.To(obj.GetNamespace()),
ResourceName: ptr.To(obj.GetName()),
Version: ptr.To(gvk.Version),
Group: ptr.To(gvk.Group),
Kind: ptr.To(gvk.Kind),
Force: &force,
Orphan: &orphan,
Project: ptr.To(project),
})
errors.CheckError(err)
log.Infof("Resource '%s' deleted", obj.GetName())
} else {
fmt.Printf("The command to delete %s/%s %s/%s was cancelled.\n", gvk.Group, gvk.Kind, obj.GetNamespace(), obj.GetName())
}
}
}

Expand Down

0 comments on commit d44d7ec

Please sign in to comment.