diff --git a/decision_maker.go b/decision_maker.go index 0eb45ad5..8105dcde 100644 --- a/decision_maker.go +++ b/decision_maker.go @@ -26,6 +26,12 @@ func makePlan(s *state) *plan { // decide makes a decision about what commands (actions) need to be executed // to make a release section of the desired state come true. func decide(r *release, s *state) { + if destroy { + if ok, rs := helmReleaseExists(r, ""); ok { + deleteRelease(r, rs) + return + } + } // check for deletion if !r.Enabled { diff --git a/init.go b/init.go index b48cd63c..d697ed22 100644 --- a/init.go +++ b/init.go @@ -43,6 +43,7 @@ func init() { flag.BoolVar(&apply, "apply", false, "apply the plan directly") flag.BoolVar(&debug, "debug", false, "show the execution logs") flag.BoolVar(&dryRun, "dry-run", false, "apply the dry-run option for helm commands.") + flag.BoolVar(&destroy, "destroy", false, "delete all deployed releases. Purge delete is used if the purge option is set to true for the releases.") flag.BoolVar(&v, "v", false, "show the version") flag.BoolVar(&verbose, "verbose", false, "show verbose execution logs") flag.BoolVar(&noBanner, "no-banner", false, "don't show the banner") @@ -71,6 +72,10 @@ func init() { logError("ERROR: --apply and --dry-run can't be used together.") } + if destroy && apply { + logError("ERROR: --destroy and --apply can't be used together.") + } + helmVersion = strings.TrimSpace(strings.SplitN(getHelmClientVersion(), ": ", 2)[1]) kubectlVersion = strings.TrimSpace(strings.SplitN(getKubectlClientVersion(), ": ", 2)[1]) @@ -128,11 +133,6 @@ func init() { } } - // print all env variables - // for _, pair := range os.Environ() { - // fmt.Println(pair) - // } - // read the TOML/YAML desired state file var fileState state for _, f := range files { diff --git a/main.go b/main.go index 89ecd606..a53eacc5 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,7 @@ var kubectlVersion string var pwd string var relativeDir string var dryRun bool +var destroy bool func main() { // set the kubecontext to be used Or create it if it does not exist @@ -81,6 +82,9 @@ func main() { } log.Println("INFO: checking what I need to do for your charts ... ") + if destroy { + log.Println("WARN: --destroy is enabled. Your releases will be deleted!") + } p := makePlan(&s) if !keepUntrackedReleases { @@ -91,7 +95,7 @@ func main() { p.printPlan() p.sendPlanToSlack() - if apply || dryRun { + if apply || dryRun || destroy { p.execPlan() }