Skip to content

Commit

Permalink
feat(prune): warn before deleting namespaces (grafana#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic authored Mar 10, 2021
1 parent 78c74d1 commit dc6caa3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/tanka/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tanka
import (
"fmt"

"github.com/fatih/color"

"github.com/grafana/tanka/pkg/kubernetes"
"github.com/grafana/tanka/pkg/term"
)
Expand Down Expand Up @@ -51,6 +53,22 @@ func Prune(baseDir string, opts PruneOpts) error {
}
fmt.Print(term.Colordiff(*diff).String())

// print namespace removal warning
namespaces := []string{}
for _, obj := range orphaned {
if obj.Kind() == "Namespace" {
namespaces = append(namespaces, obj.Metadata().Name())
}
}
if len(namespaces) > 0 {
warning := color.New(color.FgHiYellow, color.Bold).PrintFunc()
warning("WARNING: This will delete following namespaces and all resources in them:\n")
for _, ns := range namespaces {
fmt.Printf(" - %s\n", ns)
}
fmt.Println("")
}

// prompt for confirm
if opts.AutoApprove {
} else if err := confirmPrompt("Pruning from", p.Env.Spec.Namespace, kube.Info()); err != nil {
Expand Down

0 comments on commit dc6caa3

Please sign in to comment.