2019-12-19 23:02:49 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
|
|
|
type Uninstall struct {
|
2020-01-02 18:58:58 +00:00
|
|
|
Release string
|
|
|
|
DryRun bool
|
|
|
|
KeepHistory bool
|
|
|
|
cmd cmd
|
2019-12-19 23:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute executes the `helm uninstall` command.
|
|
|
|
func (u *Uninstall) Execute(_ Config) error {
|
|
|
|
return u.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the Uninstall ready to execute.
|
|
|
|
func (u *Uninstall) Prepare(cfg Config) error {
|
|
|
|
if u.Release == "" {
|
|
|
|
return fmt.Errorf("release is required")
|
|
|
|
}
|
|
|
|
|
2019-12-23 20:43:17 +00:00
|
|
|
args := make([]string, 0)
|
2019-12-19 23:02:49 +00:00
|
|
|
|
|
|
|
if cfg.Namespace != "" {
|
|
|
|
args = append(args, "--namespace", cfg.Namespace)
|
|
|
|
}
|
|
|
|
if cfg.Debug {
|
|
|
|
args = append(args, "--debug")
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, "uninstall")
|
|
|
|
|
|
|
|
if u.DryRun {
|
|
|
|
args = append(args, "--dry-run")
|
|
|
|
}
|
2020-01-02 18:58:58 +00:00
|
|
|
if u.KeepHistory {
|
|
|
|
args = append(args, "--keep-history")
|
|
|
|
}
|
2019-12-19 23:02:49 +00:00
|
|
|
|
|
|
|
args = append(args, u.Release)
|
|
|
|
|
|
|
|
u.cmd = command(helmBin, args...)
|
|
|
|
u.cmd.Stdout(cfg.Stdout)
|
|
|
|
u.cmd.Stderr(cfg.Stderr)
|
|
|
|
|
|
|
|
if cfg.Debug {
|
|
|
|
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", u.cmd.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|