2019-12-18 00:21:45 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-18 00:55:01 +00:00
|
|
|
"fmt"
|
2020-01-16 21:50:04 +00:00
|
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
2019-12-18 00:21:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lint is an execution step that calls `helm lint` when executed.
|
|
|
|
type Lint struct {
|
2020-01-17 18:13:53 +00:00
|
|
|
*config
|
|
|
|
chart string
|
|
|
|
values string
|
|
|
|
stringValues string
|
|
|
|
valuesFiles []string
|
|
|
|
strict bool
|
2020-01-02 19:38:41 +00:00
|
|
|
cmd cmd
|
2019-12-18 00:21:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
// 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{
|
2020-01-17 18:13:53 +00:00
|
|
|
config: newConfig(cfg),
|
|
|
|
chart: cfg.Chart,
|
|
|
|
values: cfg.Values,
|
|
|
|
stringValues: cfg.StringValues,
|
|
|
|
valuesFiles: cfg.ValuesFiles,
|
|
|
|
strict: cfg.LintStrictly,
|
2020-01-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 00:21:45 +00:00
|
|
|
// Execute executes the `helm lint` command.
|
2020-01-16 23:30:21 +00:00
|
|
|
func (l *Lint) Execute() error {
|
2019-12-18 00:21:45 +00:00
|
|
|
return l.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the Lint ready to execute.
|
2020-01-17 18:13:53 +00:00
|
|
|
func (l *Lint) Prepare() error {
|
|
|
|
if l.chart == "" {
|
2019-12-18 01:00:34 +00:00
|
|
|
return fmt.Errorf("chart is required")
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:12:53 +00:00
|
|
|
args := l.globalFlags()
|
2019-12-18 00:55:01 +00:00
|
|
|
args = append(args, "lint")
|
2019-12-18 00:41:09 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if l.values != "" {
|
|
|
|
args = append(args, "--set", l.values)
|
2019-12-18 00:41:09 +00:00
|
|
|
}
|
2020-01-17 18:13:53 +00:00
|
|
|
if l.stringValues != "" {
|
|
|
|
args = append(args, "--set-string", l.stringValues)
|
2019-12-18 00:41:09 +00:00
|
|
|
}
|
2020-01-17 18:13:53 +00:00
|
|
|
for _, vFile := range l.valuesFiles {
|
2019-12-18 00:41:09 +00:00
|
|
|
args = append(args, "--values", vFile)
|
|
|
|
}
|
2020-01-17 18:13:53 +00:00
|
|
|
if l.strict {
|
2020-01-02 19:25:13 +00:00
|
|
|
args = append(args, "--strict")
|
|
|
|
}
|
2019-12-18 00:41:09 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
args = append(args, l.chart)
|
2019-12-18 00:21:45 +00:00
|
|
|
|
|
|
|
l.cmd = command(helmBin, args...)
|
2020-01-17 18:13:53 +00:00
|
|
|
l.cmd.Stdout(l.stdout)
|
|
|
|
l.cmd.Stderr(l.stderr)
|
2019-12-18 00:21:45 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if l.debug {
|
|
|
|
fmt.Fprintf(l.stderr, "Generated command: '%s'\n", l.cmd.String())
|
2019-12-18 00:55:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 00:21:45 +00:00
|
|
|
return nil
|
|
|
|
}
|