2019-12-27 23:06:32 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-16 21:50:04 +00:00
|
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
2019-12-27 23:06:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DepUpdate is an execution step that calls `helm dependency update` when executed.
|
|
|
|
type DepUpdate struct {
|
|
|
|
Chart string
|
|
|
|
cmd cmd
|
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
// NewDepUpdate creates a DepUpdate using fields from the given Config. No validation is performed at this time.
|
|
|
|
func NewDepUpdate(cfg env.Config) *DepUpdate {
|
|
|
|
return &DepUpdate{
|
|
|
|
Chart: cfg.Chart,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 23:06:32 +00:00
|
|
|
// Execute executes the `helm upgrade` command.
|
2020-01-16 23:30:21 +00:00
|
|
|
func (d *DepUpdate) Execute() error {
|
2019-12-27 23:06:32 +00:00
|
|
|
return d.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the DepUpdate ready to execute.
|
|
|
|
func (d *DepUpdate) Prepare(cfg Config) error {
|
|
|
|
if d.Chart == "" {
|
|
|
|
return fmt.Errorf("chart is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
args := make([]string, 0)
|
|
|
|
|
|
|
|
if cfg.Namespace != "" {
|
|
|
|
args = append(args, "--namespace", cfg.Namespace)
|
|
|
|
}
|
|
|
|
if cfg.Debug {
|
|
|
|
args = append(args, "--debug")
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, "dependency", "update", d.Chart)
|
|
|
|
|
|
|
|
d.cmd = command(helmBin, args...)
|
|
|
|
d.cmd.Stdout(cfg.Stdout)
|
|
|
|
d.cmd.Stderr(cfg.Stderr)
|
|
|
|
|
|
|
|
if cfg.Debug {
|
|
|
|
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", d.cmd.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|