Merge branch 'master' into no-todos

This commit is contained in:
Erin Call 2019-12-17 15:35:28 -08:00
commit f3039ee35d
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
4 changed files with 113 additions and 13 deletions

View file

@ -106,6 +106,7 @@ var upgrade = func(cfg Config) []Step {
Chart: cfg.Chart, Chart: cfg.Chart,
Release: cfg.Release, Release: cfg.Release,
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: cfg.DryRun,
Wait: cfg.Wait, Wait: cfg.Wait,
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,

View file

@ -93,6 +93,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
APIServer: "123.456.78.9", APIServer: "123.456.78.9",
ServiceAccount: "helmet", ServiceAccount: "helmet",
ChartVersion: "seventeen", ChartVersion: "seventeen",
DryRun: true,
Wait: true, Wait: true,
ReuseValues: true, ReuseValues: true,
Timeout: "go sit in the corner", Timeout: "go sit in the corner",
@ -126,6 +127,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
Chart: cfg.Chart, Chart: cfg.Chart,
Release: cfg.Release, Release: cfg.Release,
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: true,
Wait: cfg.Wait, Wait: cfg.Wait,
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,

View file

@ -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
@ -25,18 +26,53 @@ func (u *Upgrade) Execute(_ Config) error {
// Prepare gets the Upgrade ready to execute. // Prepare gets the Upgrade ready to execute.
func (u *Upgrade) Prepare(cfg Config) error { func (u *Upgrade) Prepare(cfg Config) error {
if u.Chart == "" {
return fmt.Errorf("chart is required")
}
if u.Release == "" {
return fmt.Errorf("release is required")
}
args := []string{"--kubeconfig", cfg.KubeConfig} args := []string{"--kubeconfig", cfg.KubeConfig}
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)

View file

@ -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,72 @@ 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) TestRequiresChartAndRelease() {
// These aren't really expected, but allowing them gives clearer test-failure messages
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
u := Upgrade{
Release: "seth_everman_unskippable_cutscene",
}
err := u.Prepare(Config{})
suite.EqualError(err, "chart is required", "Chart should be mandatory")
u = Upgrade{
Chart: "billboard_top_zero",
}
err = u.Prepare(Config{})
suite.EqualError(err, "release is required", "Release should be mandatory")
} }
func (suite *UpgradeTestSuite) TestPrepareDebugFlag() { func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
@ -125,7 +186,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())