Skip to content

Commit

Permalink
adding destroy support. #88
Browse files Browse the repository at this point in the history
  • Loading branch information
sami-alajrami committed Sep 26, 2018
1 parent 0ca58a3 commit 6931094
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions decision_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -91,7 +95,7 @@ func main() {
p.printPlan()
p.sendPlanToSlack()

if apply || dryRun {
if apply || dryRun || destroy {
p.execPlan()
}

Expand Down

0 comments on commit 6931094

Please sign in to comment.