diff --git a/pkg/kapp/app/interfaces.go b/pkg/kapp/app/interfaces.go index ac47eea40..7f54e5c4d 100644 --- a/pkg/kapp/app/interfaces.go +++ b/pkg/kapp/app/interfaces.go @@ -24,7 +24,7 @@ type App interface { CreateOrUpdate(map[string]string, bool) error Exists() (bool, string, error) - Delete() error + Delete(bool) error Rename(string, string) error RenamePrevApp(string, map[string]string, bool) error diff --git a/pkg/kapp/app/labeled_app.go b/pkg/kapp/app/labeled_app.go index ff5128f45..d5f21c0cd 100644 --- a/pkg/kapp/app/labeled_app.go +++ b/pkg/kapp/app/labeled_app.go @@ -47,12 +47,16 @@ func (a *LabeledApp) UpdateUsedGVsAndGKs([]schema.GroupVersion, []schema.GroupKi func (a *LabeledApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) error { return nil } func (a *LabeledApp) Exists() (bool, string, error) { return true, "", nil } -func (a *LabeledApp) Delete() error { +func (a *LabeledApp) Delete(checkResourcesDeleted bool) error { labelSelector, err := a.LabelSelector() if err != nil { return err } + if !checkResourcesDeleted { + return nil + } + rs, err := a.identifiedResources.List(labelSelector, nil, ctlres.IdentifiedResourcesListOpts{IgnoreCachedResTypes: true}) if err != nil { return fmt.Errorf("Relisting app resources: %w", err) diff --git a/pkg/kapp/app/recorded_app.go b/pkg/kapp/app/recorded_app.go index ab022f6ab..442f7ae6e 100644 --- a/pkg/kapp/app/recorded_app.go +++ b/pkg/kapp/app/recorded_app.go @@ -353,7 +353,7 @@ func (a *RecordedApp) Exists() (bool, string, error) { return true, "", nil } -func (a *RecordedApp) Delete() error { +func (a *RecordedApp) Delete(checkResourcesDeleted bool) error { app, err := a.labeledApp() if err != nil { return err @@ -364,7 +364,7 @@ func (a *RecordedApp) Delete() error { return fmt.Errorf("Deleting app changes: %w", err) } - err = app.Delete() + err = app.Delete(checkResourcesDeleted) if err != nil { return err } diff --git a/pkg/kapp/cmd/app/delete.go b/pkg/kapp/cmd/app/delete.go index 97613d62e..226822603 100644 --- a/pkg/kapp/cmd/app/delete.go +++ b/pkg/kapp/cmd/app/delete.go @@ -29,6 +29,7 @@ type DeleteOptions struct { ApplyFlags ApplyFlags ResourceTypesFlags ResourceTypesFlags PrevAppFlags PrevAppFlags + DeleteFlags DeleteFlags } type changesSummary struct { @@ -56,6 +57,7 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co o.ApplyFlags.SetWithDefaults("", ApplyFlagsDeleteDefaults, cmd) o.ResourceTypesFlags.Set(cmd) o.PrevAppFlags.Set(cmd) + o.DeleteFlags.Set(cmd) return cmd } @@ -157,7 +159,7 @@ func (o *DeleteOptions) Run() error { return err } if shouldFullyDeleteApp { - return app.Delete() + return app.Delete(o.DeleteFlags.DisableCheckingResourceDeletion) } return nil }) diff --git a/pkg/kapp/cmd/app/delete_flags.go b/pkg/kapp/cmd/app/delete_flags.go new file mode 100644 index 000000000..de2925e1d --- /dev/null +++ b/pkg/kapp/cmd/app/delete_flags.go @@ -0,0 +1,15 @@ +// Copyright 2022 VMware, Inc. +// SPDX-License-Identifier: Apache-2.0 + +package app + +import "github.com/spf13/cobra" + +type DeleteFlags struct { + DisableCheckingResourceDeletion bool +} + +func (s *DeleteFlags) Set(cmd *cobra.Command) { + cmd.Flags().BoolVar(&s.DisableCheckingResourceDeletion, "dangerous-disable-checking-resource-deletion", + false, "Skip checking resource deletion when fully deleting app") +}