Put step-specific config in those steps [#61]

This is just something that's been bugging me for a while--they're
specific to Lint and Upgrade, so that's where they belong.
This commit is contained in:
Erin Call 2020-01-02 11:38:41 -08:00
parent 7d750f097d
commit 4330728215
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
7 changed files with 68 additions and 58 deletions

View file

@ -29,13 +29,10 @@ func NewPlan(cfg Config) (*Plan, error) {
p := Plan{ p := Plan{
cfg: cfg, cfg: cfg,
runCfg: run.Config{ runCfg: run.Config{
Debug: cfg.Debug, Debug: cfg.Debug,
Values: cfg.Values, Namespace: cfg.Namespace,
StringValues: cfg.StringValues, Stdout: cfg.Stdout,
ValuesFiles: cfg.ValuesFiles, Stderr: cfg.Stderr,
Namespace: cfg.Namespace,
Stdout: cfg.Stdout,
Stderr: cfg.Stderr,
}, },
} }
@ -106,6 +103,9 @@ var upgrade = func(cfg Config) []Step {
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: cfg.DryRun, DryRun: cfg.DryRun,
Wait: cfg.Wait, Wait: cfg.Wait,
Values: cfg.Values,
StringValues: cfg.StringValues,
ValuesFiles: cfg.ValuesFiles,
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,
Force: cfg.Force, Force: cfg.Force,
@ -133,7 +133,10 @@ var lint = func(cfg Config) []Step {
steps = append(steps, depUpdate(cfg)...) steps = append(steps, depUpdate(cfg)...)
} }
steps = append(steps, &run.Lint{ steps = append(steps, &run.Lint{
Chart: cfg.Chart, Chart: cfg.Chart,
Values: cfg.Values,
StringValues: cfg.StringValues,
ValuesFiles: cfg.ValuesFiles,
}) })
return steps return steps

View file

@ -33,24 +33,18 @@ func (suite *PlanTestSuite) TestNewPlan() {
stdout := strings.Builder{} stdout := strings.Builder{}
stderr := strings.Builder{} stderr := strings.Builder{}
cfg := Config{ cfg := Config{
Command: "help", Command: "help",
Debug: false, Debug: false,
Values: "steadfastness,forthrightness", Namespace: "outer",
StringValues: "tensile_strength,flexibility", Stdout: &stdout,
ValuesFiles: []string{"/root/price_inventory.yml"}, Stderr: &stderr,
Namespace: "outer",
Stdout: &stdout,
Stderr: &stderr,
} }
runCfg := run.Config{ runCfg := run.Config{
Debug: false, Debug: false,
Values: "steadfastness,forthrightness", Namespace: "outer",
StringValues: "tensile_strength,flexibility", Stdout: &stdout,
ValuesFiles: []string{"/root/price_inventory.yml"}, Stderr: &stderr,
Namespace: "outer",
Stdout: &stdout,
Stderr: &stderr,
} }
stepOne.EXPECT(). stepOne.EXPECT().
@ -139,6 +133,9 @@ func (suite *PlanTestSuite) TestUpgrade() {
ChartVersion: "seventeen", ChartVersion: "seventeen",
DryRun: true, DryRun: true,
Wait: true, Wait: true,
Values: "steadfastness,forthrightness",
StringValues: "tensile_strength,flexibility",
ValuesFiles: []string{"/root/price_inventory.yml"},
ReuseValues: true, ReuseValues: true,
Timeout: "go sit in the corner", Timeout: "go sit in the corner",
Chart: "billboard_top_100", Chart: "billboard_top_100",
@ -159,6 +156,9 @@ func (suite *PlanTestSuite) TestUpgrade() {
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: true, DryRun: true,
Wait: cfg.Wait, Wait: cfg.Wait,
Values: "steadfastness,forthrightness",
StringValues: "tensile_strength,flexibility",
ValuesFiles: []string{"/root/price_inventory.yml"},
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,
Force: cfg.Force, Force: cfg.Force,
@ -299,14 +299,20 @@ func (suite *PlanTestSuite) TestAddRepos() {
func (suite *PlanTestSuite) TestLint() { func (suite *PlanTestSuite) TestLint() {
cfg := Config{ cfg := Config{
Chart: "./flow", Chart: "./flow",
Values: "steadfastness,forthrightness",
StringValues: "tensile_strength,flexibility",
ValuesFiles: []string{"/root/price_inventory.yml"},
} }
steps := lint(cfg) steps := lint(cfg)
suite.Equal(1, len(steps)) suite.Equal(1, len(steps))
want := &run.Lint{ want := &run.Lint{
Chart: "./flow", Chart: "./flow",
Values: "steadfastness,forthrightness",
StringValues: "tensile_strength,flexibility",
ValuesFiles: []string{"/root/price_inventory.yml"},
} }
suite.Equal(want, steps[0]) suite.Equal(want, steps[0])
} }

View file

@ -6,11 +6,8 @@ import (
// Config contains configuration applicable to all helm commands // Config contains configuration applicable to all helm commands
type Config struct { type Config struct {
Debug bool Debug bool
Values string Namespace string
StringValues string Stdout io.Writer
ValuesFiles []string Stderr io.Writer
Namespace string
Stdout io.Writer
Stderr io.Writer
} }

View file

@ -6,8 +6,11 @@ import (
// Lint is an execution step that calls `helm lint` when executed. // Lint is an execution step that calls `helm lint` when executed.
type Lint struct { type Lint struct {
Chart string Chart string
cmd cmd Values string
StringValues string
ValuesFiles []string
cmd cmd
} }
// Execute executes the `helm lint` command. // Execute executes the `helm lint` command.
@ -32,13 +35,13 @@ func (l *Lint) Prepare(cfg Config) error {
args = append(args, "lint") args = append(args, "lint")
if cfg.Values != "" { if l.Values != "" {
args = append(args, "--set", cfg.Values) args = append(args, "--set", l.Values)
} }
if cfg.StringValues != "" { if l.StringValues != "" {
args = append(args, "--set-string", cfg.StringValues) args = append(args, "--set-string", l.StringValues)
} }
for _, vFile := range cfg.ValuesFiles { for _, vFile := range l.ValuesFiles {
args = append(args, "--values", vFile) args = append(args, "--values", vFile)
} }

View file

@ -80,16 +80,15 @@ func (suite *LintTestSuite) TestPrepareRequiresChart() {
func (suite *LintTestSuite) TestPrepareWithLintFlags() { func (suite *LintTestSuite) TestPrepareWithLintFlags() {
defer suite.ctrl.Finish() defer suite.ctrl.Finish()
cfg := Config{ cfg := Config{}
l := Lint{
Chart: "./uk/top_40",
Values: "width=5", Values: "width=5",
StringValues: "version=2.0", StringValues: "version=2.0",
ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"}, ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"},
} }
l := Lint{
Chart: "./uk/top_40",
}
command = func(path string, args ...string) cmd { command = func(path string, args ...string) cmd {
suite.Equal(helmBin, path) suite.Equal(helmBin, path)
suite.Equal([]string{"lint", suite.Equal([]string{"lint",

View file

@ -12,6 +12,9 @@ type Upgrade struct {
ChartVersion string ChartVersion string
DryRun bool DryRun bool
Wait bool Wait bool
Values string
StringValues string
ValuesFiles []string
ReuseValues bool ReuseValues bool
Timeout string Timeout string
Force bool Force bool
@ -62,13 +65,13 @@ func (u *Upgrade) Prepare(cfg Config) error {
if u.Force { if u.Force {
args = append(args, "--force") args = append(args, "--force")
} }
if cfg.Values != "" { if u.Values != "" {
args = append(args, "--set", cfg.Values) args = append(args, "--set", u.Values)
} }
if cfg.StringValues != "" { if u.StringValues != "" {
args = append(args, "--set-string", cfg.StringValues) args = append(args, "--set-string", u.StringValues)
} }
for _, vFile := range cfg.ValuesFiles { for _, vFile := range u.ValuesFiles {
args = append(args, "--values", vFile) args = append(args, "--values", vFile)
} }

View file

@ -91,20 +91,19 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
u := Upgrade{ u := Upgrade{
Chart: "hot_ac", Chart: "hot_ac",
Release: "maroon_5_memories", Release: "maroon_5_memories",
ChartVersion: "radio_edit", //-version ChartVersion: "radio_edit",
DryRun: true, //-run DryRun: true,
Wait: true, //-wait Wait: true,
ReuseValues: true, //-values
Timeout: "sit_in_the_corner", //-timeout
Force: true, //-force
}
cfg := Config{
Values: "age=35", Values: "age=35",
StringValues: "height=5ft10in", StringValues: "height=5ft10in",
ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"}, ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"},
ReuseValues: true,
Timeout: "sit_in_the_corner",
Force: true,
} }
cfg := Config{}
command = func(path string, args ...string) cmd { command = func(path string, args ...string) cmd {
suite.Equal(helmBin, path) suite.Equal(helmBin, path)
suite.Equal([]string{"upgrade", "--install", suite.Equal([]string{"upgrade", "--install",