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
|
|
|
|
|
|
|
ChartVersion string
|
2019-12-17 00:55:05 +00:00
|
|
|
DryRun bool
|
2019-12-10 00:25:47 +00:00
|
|
|
Wait bool
|
|
|
|
ReuseValues bool
|
|
|
|
Timeout string
|
|
|
|
Force bool
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
if cfg.Values != "" {
|
|
|
|
args = append(args, "--set", cfg.Values)
|
|
|
|
}
|
|
|
|
if cfg.StringValues != "" {
|
|
|
|
args = append(args, "--set-string", cfg.StringValues)
|
|
|
|
}
|
|
|
|
for _, vFile := range cfg.ValuesFiles {
|
|
|
|
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
|
|
|
}
|