Implement config flags for helm upgrade
This commit is contained in:
parent
c08b2035a8
commit
e4fa70239e
|
@ -10,6 +10,7 @@ type Upgrade struct {
|
|||
Release string
|
||||
|
||||
ChartVersion string
|
||||
DryRun bool
|
||||
Wait bool
|
||||
ReuseValues bool
|
||||
Timeout string
|
||||
|
@ -30,13 +31,41 @@ func (u *Upgrade) Prepare(cfg Config) error {
|
|||
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...)
|
||||
args = append(args, "--debug")
|
||||
}
|
||||
|
||||
args = append(args, "upgrade", "--install")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
args = append(args, u.Release, u.Chart)
|
||||
u.cmd = command(helmBin, args...)
|
||||
u.cmd.Stdout(cfg.Stdout)
|
||||
u.cmd.Stderr(cfg.Stderr)
|
||||
|
|
|
@ -31,7 +31,7 @@ func TestUpgradeTestSuite(t *testing.T) {
|
|||
suite.Run(t, new(UpgradeTestSuite))
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepare() {
|
||||
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Upgrade{
|
||||
|
@ -79,12 +79,8 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
|||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Stderr(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Run()
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||
|
||||
cfg := Config{
|
||||
Namespace: "melt",
|
||||
|
@ -92,7 +88,52 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
|||
}
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
u.Execute(cfg)
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Upgrade{
|
||||
Chart: "hot_ac",
|
||||
Release: "maroon_5_memories",
|
||||
ChartVersion: "radio_edit", //-version
|
||||
DryRun: true, //-run
|
||||
Wait: true, //-wait
|
||||
ReuseValues: true, //-values
|
||||
Timeout: "sit_in_the_corner", //-timeout
|
||||
Force: true, //-force
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Values: "age=35",
|
||||
StringValues: "height=5ft10in",
|
||||
ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"},
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"--kubeconfig", "/root/.kube/config", "upgrade", "--install",
|
||||
"--version", "radio_edit",
|
||||
"--dry-run",
|
||||
"--wait",
|
||||
"--reuse-values",
|
||||
"--timeout", "sit_in_the_corner",
|
||||
"--force",
|
||||
"--set", "age=35",
|
||||
"--set-string", "height=5ft10in",
|
||||
"--values", "/usr/local/stats",
|
||||
"--values", "/usr/local/grades",
|
||||
"maroon_5_memories", "hot_ac"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||
|
@ -125,7 +166,7 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
|||
|
||||
u.Prepare(cfg)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug --kubeconfig /root/.kube/config upgrade "+
|
||||
want := fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config --debug upgrade "+
|
||||
"--install lewis_capaldi_someone_you_loved at40'\n", helmBin)
|
||||
suite.Equal(want, stderr.String())
|
||||
suite.Equal("", stdout.String())
|
||||
|
|
Loading…
Reference in a new issue