Skip to content

Commit

Permalink
Add flag to skip checking resource when fully deleting app
Browse files Browse the repository at this point in the history
  • Loading branch information
firgavin committed Sep 3, 2022
1 parent e7d9e9f commit 7c0439b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/kapp/app/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type App interface {

CreateOrUpdate(map[string]string, bool) error
Exists() (bool, string, error)
Delete() error
Delete(checkResource bool) error
Rename(string, string) error
RenamePrevApp(string, map[string]string, bool) error

Expand Down
12 changes: 7 additions & 5 deletions pkg/kapp/app/labeled_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ 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(checkResource bool) error {
labelSelector, err := a.LabelSelector()
if err != nil {
return err
Expand All @@ -59,11 +59,13 @@ func (a *LabeledApp) Delete() error {
}

if len(rs) > 0 {
var resourceNames []string
for _, res := range rs {
resourceNames = append(resourceNames, res.Description())
if checkResource {
var resourceNames []string
for _, res := range rs {
resourceNames = append(resourceNames, res.Description())
}
return fmt.Errorf("Expected all resources to be gone, but found: %s", strings.Join(resourceNames, ", "))
}
return fmt.Errorf("Expected all resources to be gone, but found: %s", strings.Join(resourceNames, ", "))
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (a *RecordedApp) Exists() (bool, string, error) {
return true, "", nil
}

func (a *RecordedApp) Delete() error {
func (a *RecordedApp) Delete(checkResource bool) error {
app, err := a.labeledApp()
if err != nil {
return err
Expand All @@ -364,7 +364,7 @@ func (a *RecordedApp) Delete() error {
return fmt.Errorf("Deleting app changes: %w", err)
}

err = app.Delete()
err = app.Delete(checkResource)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/kapp/cmd/app/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type DeleteOptions struct {
ApplyFlags ApplyFlags
ResourceTypesFlags ResourceTypesFlags
PrevAppFlags PrevAppFlags
DeleteFlags DeleteFlags
}

type changesSummary struct {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -157,7 +159,7 @@ func (o *DeleteOptions) Run() error {
return err
}
if shouldFullyDeleteApp {
return app.Delete()
return app.Delete(o.DeleteFlags.DisableCheckingResourceDeletion)
}
return nil
})
Expand Down
15 changes: 15 additions & 0 deletions pkg/kapp/cmd/app/delete_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2020 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")
}

0 comments on commit 7c0439b

Please sign in to comment.