2019-12-19 23:02:49 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-16 21:50:04 +00:00
|
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
2019-12-19 23:02:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
|
|
|
type Uninstall struct {
|
2020-01-17 18:13:53 +00:00
|
|
|
*config
|
|
|
|
release string
|
|
|
|
dryRun bool
|
|
|
|
keepHistory bool
|
2020-01-02 18:58:58 +00:00
|
|
|
cmd cmd
|
2019-12-19 23:02:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
// NewUninstall creates an Uninstall using fields from the given Config. No validation is performed at this time.
|
|
|
|
func NewUninstall(cfg env.Config) *Uninstall {
|
|
|
|
return &Uninstall{
|
2020-01-17 18:13:53 +00:00
|
|
|
config: newConfig(cfg),
|
|
|
|
release: cfg.Release,
|
|
|
|
dryRun: cfg.DryRun,
|
|
|
|
keepHistory: cfg.KeepHistory,
|
2020-01-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:02:49 +00:00
|
|
|
// Execute executes the `helm uninstall` command.
|
2020-01-16 23:30:21 +00:00
|
|
|
func (u *Uninstall) Execute() error {
|
2019-12-19 23:02:49 +00:00
|
|
|
return u.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the Uninstall ready to execute.
|
2020-01-17 18:13:53 +00:00
|
|
|
func (u *Uninstall) Prepare() error {
|
|
|
|
if u.release == "" {
|
2019-12-19 23:02:49 +00:00
|
|
|
return fmt.Errorf("release is required")
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:12:53 +00:00
|
|
|
args := u.globalFlags()
|
2019-12-19 23:02:49 +00:00
|
|
|
args = append(args, "uninstall")
|
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if u.dryRun {
|
2019-12-19 23:02:49 +00:00
|
|
|
args = append(args, "--dry-run")
|
|
|
|
}
|
2020-01-17 18:13:53 +00:00
|
|
|
if u.keepHistory {
|
2020-01-02 18:58:58 +00:00
|
|
|
args = append(args, "--keep-history")
|
|
|
|
}
|
2019-12-19 23:02:49 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
args = append(args, u.release)
|
2019-12-19 23:02:49 +00:00
|
|
|
|
|
|
|
u.cmd = command(helmBin, args...)
|
2020-01-17 18:13:53 +00:00
|
|
|
u.cmd.Stdout(u.stdout)
|
|
|
|
u.cmd.Stderr(u.stderr)
|
2019-12-19 23:02:49 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if u.debug {
|
|
|
|
fmt.Fprintf(u.stderr, "Generated command: '%s'\n", u.cmd.String())
|
2019-12-19 23:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|