2019-12-05 22:35:25 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-10 00:25:47 +00:00
|
|
|
"fmt"
|
2019-12-05 22:35:25 +00:00
|
|
|
)
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Upgrade is an execution step that calls `helm upgrade` when executed.
|
2019-12-09 17:56:02 +00:00
|
|
|
type Upgrade struct {
|
|
|
|
Chart string
|
|
|
|
Release string
|
2019-12-10 00:25:47 +00:00
|
|
|
|
2020-01-07 20:53:55 +00:00
|
|
|
ChartVersion string
|
|
|
|
DryRun bool
|
|
|
|
Wait bool
|
|
|
|
Values string
|
|
|
|
StringValues string
|
|
|
|
ValuesFiles []string
|
|
|
|
ReuseValues bool
|
|
|
|
Timeout string
|
|
|
|
Force bool
|
|
|
|
Atomic bool
|
|
|
|
CleanupOnFail bool
|
2019-12-10 00:25:47 +00:00
|
|
|
|
|
|
|
cmd cmd
|
2019-12-09 17:56:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Execute executes the `helm upgrade` command.
|
2019-12-12 18:20:11 +00:00
|
|
|
func (u *Upgrade) Execute(_ Config) error {
|
2019-12-09 17:56:02 +00:00
|
|
|
return u.cmd.Run()
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Prepare gets the Upgrade ready to execute.
|
|
|
|
func (u *Upgrade) Prepare(cfg Config) error {
|
2019-12-17 00:55:54 +00:00
|
|
|
if u.Chart == "" {
|
|
|
|
return fmt.Errorf("chart is required")
|
|
|
|
}
|
|
|
|
if u.Release == "" {
|
|
|
|
return fmt.Errorf("release is required")
|
|
|
|
}
|
|
|
|
|
2019-12-23 20:43:17 +00:00
|
|
|
args := make([]string, 0)
|
2019-12-12 18:20:11 +00:00
|
|
|
|
|
|
|
if cfg.Namespace != "" {
|
|
|
|
args = append(args, "--namespace", cfg.Namespace)
|
|
|
|
}
|
2019-12-17 00:55:05 +00:00
|
|
|
if cfg.Debug {
|
|
|
|
args = append(args, "--debug")
|
|
|
|
}
|
2019-12-12 18:20:11 +00:00
|
|
|
|
2019-12-17 00:55:05 +00:00
|
|
|
args = append(args, "upgrade", "--install")
|
2019-12-10 00:25:47 +00:00
|
|
|
|
2019-12-17 00:55:05 +00:00
|
|
|
if u.ChartVersion != "" {
|
|
|
|
args = append(args, "--version", u.ChartVersion)
|
|
|
|
}
|
|
|
|
if u.DryRun {
|
|
|
|
args = append(args, "--dry-run")
|
|
|
|
}
|
|
|
|
if u.Wait {
|
|
|
|
args = append(args, "--wait")
|
|
|
|
}
|
|
|
|
if u.ReuseValues {
|
|
|
|
args = append(args, "--reuse-values")
|
|
|
|
}
|
|
|
|
if u.Timeout != "" {
|
|
|
|
args = append(args, "--timeout", u.Timeout)
|
|
|
|
}
|
|
|
|
if u.Force {
|
|
|
|
args = append(args, "--force")
|
|
|
|
}
|
2020-01-07 20:17:54 +00:00
|
|
|
if u.Atomic {
|
|
|
|
args = append(args, "--atomic")
|
|
|
|
}
|
2020-01-07 20:53:55 +00:00
|
|
|
if u.CleanupOnFail {
|
|
|
|
args = append(args, "--cleanup-on-fail")
|
|
|
|
}
|
2020-01-02 19:38:41 +00:00
|
|
|
if u.Values != "" {
|
|
|
|
args = append(args, "--set", u.Values)
|
2019-12-17 00:55:05 +00:00
|
|
|
}
|
2020-01-02 19:38:41 +00:00
|
|
|
if u.StringValues != "" {
|
|
|
|
args = append(args, "--set-string", u.StringValues)
|
2019-12-17 00:55:05 +00:00
|
|
|
}
|
2020-01-02 19:38:41 +00:00
|
|
|
for _, vFile := range u.ValuesFiles {
|
2019-12-17 00:55:05 +00:00
|
|
|
args = append(args, "--values", vFile)
|
2019-12-09 17:56:02 +00:00
|
|
|
}
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2019-12-17 00:55:05 +00:00
|
|
|
args = append(args, u.Release, u.Chart)
|
2019-12-10 00:25:47 +00:00
|
|
|
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())
|
|
|
|
}
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
return nil
|
2019-12-05 22:35:25 +00:00
|
|
|
}
|