2019-12-18 00:21:45 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-18 00:55:01 +00:00
|
|
|
"fmt"
|
2019-12-18 00:21:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lint is an execution step that calls `helm lint` when executed.
|
|
|
|
type Lint struct {
|
2020-01-02 19:38:41 +00:00
|
|
|
Chart string
|
|
|
|
Values string
|
|
|
|
StringValues string
|
|
|
|
ValuesFiles []string
|
2020-01-02 20:29:15 +00:00
|
|
|
Strict bool
|
2020-01-02 19:38:41 +00:00
|
|
|
cmd cmd
|
2019-12-18 00:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute executes the `helm lint` command.
|
|
|
|
func (l *Lint) Execute(_ Config) error {
|
|
|
|
return l.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the Lint ready to execute.
|
|
|
|
func (l *Lint) Prepare(cfg Config) error {
|
2019-12-18 01:00:34 +00:00
|
|
|
if l.Chart == "" {
|
|
|
|
return fmt.Errorf("chart is required")
|
|
|
|
}
|
|
|
|
|
2019-12-18 00:55:01 +00:00
|
|
|
args := make([]string, 0)
|
|
|
|
|
2019-12-18 18:38:33 +00:00
|
|
|
if cfg.Namespace != "" {
|
|
|
|
args = append(args, "--namespace", cfg.Namespace)
|
|
|
|
}
|
2019-12-18 00:55:01 +00:00
|
|
|
if cfg.Debug {
|
|
|
|
args = append(args, "--debug")
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, "lint")
|
2019-12-18 00:41:09 +00:00
|
|
|
|
2020-01-02 19:38:41 +00:00
|
|
|
if l.Values != "" {
|
|
|
|
args = append(args, "--set", l.Values)
|
2019-12-18 00:41:09 +00:00
|
|
|
}
|
2020-01-02 19:38:41 +00:00
|
|
|
if l.StringValues != "" {
|
|
|
|
args = append(args, "--set-string", l.StringValues)
|
2019-12-18 00:41:09 +00:00
|
|
|
}
|
2020-01-02 19:38:41 +00:00
|
|
|
for _, vFile := range l.ValuesFiles {
|
2019-12-18 00:41:09 +00:00
|
|
|
args = append(args, "--values", vFile)
|
|
|
|
}
|
2020-01-02 19:25:13 +00:00
|
|
|
if l.Strict {
|
|
|
|
args = append(args, "--strict")
|
|
|
|
}
|
2019-12-18 00:41:09 +00:00
|
|
|
|
|
|
|
args = append(args, l.Chart)
|
2019-12-18 00:21:45 +00:00
|
|
|
|
|
|
|
l.cmd = command(helmBin, args...)
|
|
|
|
l.cmd.Stdout(cfg.Stdout)
|
|
|
|
l.cmd.Stderr(cfg.Stderr)
|
|
|
|
|
2019-12-18 00:55:01 +00:00
|
|
|
if cfg.Debug {
|
|
|
|
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", l.cmd.String())
|
|
|
|
}
|
|
|
|
|
2019-12-18 00:21:45 +00:00
|
|
|
return nil
|
|
|
|
}
|