woodpecker-helm3/internal/run/upgrade.go
Erin Call 13c663e906
Initialize kubernetes config on upgrade
This change revealed more about how the system needs to work, so there
are some supporting changes:

* helm.upgrade and helm.help are now vars rather than raw functions.
    This allows unit tests to target the "which step should we run"
    logic directly by comparing function pointers, rather than having to
    configure/prepare a fully-valid Plan and then infer the logic’s
    correctness based on the Plan’s state.
* configuration that's specific to kubeconfig initialization is now part
    of the InitKube struct rather than run.Config, since other steps
    shouldn’t need access to those settings (particularly the secrets).
* Step.Execute now receives a run.Config so it can log debug output.
2019-12-16 15:41:04 -08:00

50 lines
937 B
Go

package run
import (
"fmt"
)
// Upgrade is an execution step that calls `helm upgrade` when executed.
type Upgrade struct {
Chart string
Release string
ChartVersion string
Wait bool
ReuseValues bool
Timeout string
Force bool
cmd cmd
}
// Execute executes the `helm upgrade` command.
func (u *Upgrade) Execute(_ Config) error {
return u.cmd.Run()
}
// Prepare gets the Upgrade ready to execute.
func (u *Upgrade) Prepare(cfg Config) error {
args := []string{"--kubeconfig", cfg.KubeConfig}
if cfg.Namespace != "" {
args = append(args, "--namespace", cfg.Namespace)
}
args = append(args, "upgrade", "--install", u.Release, u.Chart)
if cfg.Debug {
args = append([]string{"--debug"}, args...)
}
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
}