Initialize run.Configs in the NewSTEP functions [#67]

This fixes the run package's leaky abstraction; other packages no longer
need to know or care that run.Config even exists.

Note that since the various Steps now depend on having a non-nil pointer
to a run.Config, it's unsafe (or at least risky) to initialize them
directly. They should be created with their NewSTEPNAME functions. All
their fields are now private, to reflect this.
This commit is contained in:
Erin Call
2020-01-17 10:13:53 -08:00
parent d8ddb79ef4
commit a21848484b
19 changed files with 408 additions and 447 deletions

View File

@@ -7,22 +7,24 @@ import (
// Lint is an execution step that calls `helm lint` when executed.
type Lint struct {
Chart string
Values string
StringValues string
ValuesFiles []string
Strict bool
*config
chart string
values string
stringValues string
valuesFiles []string
strict bool
cmd cmd
}
// NewLint creates a Lint using fields from the given Config. No validation is performed at this time.
func NewLint(cfg env.Config) *Lint {
return &Lint{
Chart: cfg.Chart,
Values: cfg.Values,
StringValues: cfg.StringValues,
ValuesFiles: cfg.ValuesFiles,
Strict: cfg.LintStrictly,
config: newConfig(cfg),
chart: cfg.Chart,
values: cfg.Values,
stringValues: cfg.StringValues,
valuesFiles: cfg.ValuesFiles,
strict: cfg.LintStrictly,
}
}
@@ -32,43 +34,43 @@ func (l *Lint) Execute() error {
}
// Prepare gets the Lint ready to execute.
func (l *Lint) Prepare(cfg Config) error {
if l.Chart == "" {
func (l *Lint) Prepare() error {
if l.chart == "" {
return fmt.Errorf("chart is required")
}
args := make([]string, 0)
if cfg.Namespace != "" {
args = append(args, "--namespace", cfg.Namespace)
if l.namespace != "" {
args = append(args, "--namespace", l.namespace)
}
if cfg.Debug {
if l.debug {
args = append(args, "--debug")
}
args = append(args, "lint")
if l.Values != "" {
args = append(args, "--set", l.Values)
if l.values != "" {
args = append(args, "--set", l.values)
}
if l.StringValues != "" {
args = append(args, "--set-string", l.StringValues)
if l.stringValues != "" {
args = append(args, "--set-string", l.stringValues)
}
for _, vFile := range l.ValuesFiles {
for _, vFile := range l.valuesFiles {
args = append(args, "--values", vFile)
}
if l.Strict {
if l.strict {
args = append(args, "--strict")
}
args = append(args, l.Chart)
args = append(args, l.chart)
l.cmd = command(helmBin, args...)
l.cmd.Stdout(cfg.Stdout)
l.cmd.Stderr(cfg.Stderr)
l.cmd.Stdout(l.stdout)
l.cmd.Stderr(l.stderr)
if cfg.Debug {
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", l.cmd.String())
if l.debug {
fmt.Fprintf(l.stderr, "Generated command: '%s'\n", l.cmd.String())
}
return nil