Implement config flags for helm upgrade
This commit is contained in:
parent
c08b2035a8
commit
e4fa70239e
|
@ -10,6 +10,7 @@ type Upgrade struct {
|
||||||
Release string
|
Release string
|
||||||
|
|
||||||
ChartVersion string
|
ChartVersion string
|
||||||
|
DryRun bool
|
||||||
Wait bool
|
Wait bool
|
||||||
ReuseValues bool
|
ReuseValues bool
|
||||||
Timeout string
|
Timeout string
|
||||||
|
@ -30,13 +31,41 @@ func (u *Upgrade) Prepare(cfg Config) error {
|
||||||
if cfg.Namespace != "" {
|
if cfg.Namespace != "" {
|
||||||
args = append(args, "--namespace", cfg.Namespace)
|
args = append(args, "--namespace", cfg.Namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, "upgrade", "--install", u.Release, u.Chart)
|
|
||||||
|
|
||||||
if cfg.Debug {
|
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 = command(helmBin, args...)
|
||||||
u.cmd.Stdout(cfg.Stdout)
|
u.cmd.Stdout(cfg.Stdout)
|
||||||
u.cmd.Stderr(cfg.Stderr)
|
u.cmd.Stderr(cfg.Stderr)
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestUpgradeTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(UpgradeTestSuite))
|
suite.Run(t, new(UpgradeTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *UpgradeTestSuite) TestPrepare() {
|
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
u := Upgrade{
|
u := Upgrade{
|
||||||
|
@ -79,12 +79,8 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||||
return suite.mockCmd
|
return suite.mockCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.mockCmd.EXPECT().
|
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||||
Stdout(gomock.Any())
|
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||||
suite.mockCmd.EXPECT().
|
|
||||||
Stderr(gomock.Any())
|
|
||||||
suite.mockCmd.EXPECT().
|
|
||||||
Run()
|
|
||||||
|
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Namespace: "melt",
|
Namespace: "melt",
|
||||||
|
@ -92,7 +88,52 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||||
}
|
}
|
||||||
err := u.Prepare(cfg)
|
err := u.Prepare(cfg)
|
||||||
suite.Require().Nil(err)
|
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() {
|
func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||||
|
@ -125,7 +166,7 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||||
|
|
||||||
u.Prepare(cfg)
|
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)
|
"--install lewis_capaldi_someone_you_loved at40'\n", helmBin)
|
||||||
suite.Equal(want, stderr.String())
|
suite.Equal(want, stderr.String())
|
||||||
suite.Equal("", stdout.String())
|
suite.Equal("", stdout.String())
|
||||||
|
|
Loading…
Reference in a new issue