Add helmfile-fetch command to downloading and generating charts (#1734)
This commit is contained in:
parent
faa74962e6
commit
53c6d2f988
30
main.go
30
main.go
|
|
@ -327,6 +327,28 @@ func main() {
|
||||||
return run.Lint(c)
|
return run.Lint(c)
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "fetch",
|
||||||
|
Usage: "fetch charts from state file",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "concurrency",
|
||||||
|
Value: 0,
|
||||||
|
Usage: "maximum number of concurrent downloads of release charts",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "skip-deps",
|
||||||
|
Usage: `skip running "helm repo update" and "helm dependency build"`,
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "output-dir",
|
||||||
|
Usage: "directory to store charts (default: temporary directory which is deleted when the command terminates)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: action(func(a *app.App, c configImpl) error {
|
||||||
|
return a.Fetch(c)
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "sync",
|
Name: "sync",
|
||||||
Usage: "sync all resources from state file (repos, releases and chart deps)",
|
Usage: "sync all resources from state file (repos, releases and chart deps)",
|
||||||
|
|
@ -553,6 +575,10 @@ func main() {
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "output releases list as a json string",
|
Usage: "output releases list as a json string",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "keep-temp-dir",
|
||||||
|
Usage: "Keep temporary directory",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: action(func(run *app.App, c configImpl) error {
|
Action: action(func(run *app.App, c configImpl) error {
|
||||||
return run.ListReleases(c)
|
return run.ListReleases(c)
|
||||||
|
|
@ -720,6 +746,10 @@ func (c configImpl) Output() string {
|
||||||
return c.c.String("output")
|
return c.c.String("output")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configImpl) KeepTempDir() bool {
|
||||||
|
return c.c.Bool("keep-temp-dir")
|
||||||
|
}
|
||||||
|
|
||||||
// GlobalConfig
|
// GlobalConfig
|
||||||
|
|
||||||
func (c configImpl) HelmBinary() string {
|
func (c configImpl) HelmBinary() string {
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,24 @@ func (a *App) Lint(c LintConfigProvider) error {
|
||||||
}, SetFilter(true))
|
}, SetFilter(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) Fetch(c FetchConfigProvider) error {
|
||||||
|
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
|
||||||
|
prepErr := run.withPreparedCharts("pull", state.ChartPrepareOptions{
|
||||||
|
ForceDownload: true,
|
||||||
|
SkipRepos: c.SkipDeps(),
|
||||||
|
SkipDeps: c.SkipDeps(),
|
||||||
|
OutputDir: c.OutputDir(),
|
||||||
|
}, func() {
|
||||||
|
})
|
||||||
|
|
||||||
|
if prepErr != nil {
|
||||||
|
errs = append(errs, prepErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}, SetFilter(true))
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) Sync(c SyncConfigProvider) error {
|
func (a *App) Sync(c SyncConfigProvider) error {
|
||||||
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
|
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
|
||||||
prepErr := run.withPreparedCharts("sync", state.ChartPrepareOptions{
|
prepErr := run.withPreparedCharts("sync", state.ChartPrepareOptions{
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,13 @@ type LintConfigProvider interface {
|
||||||
concurrencyConfig
|
concurrencyConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FetchConfigProvider interface {
|
||||||
|
SkipDeps() bool
|
||||||
|
OutputDir() string
|
||||||
|
|
||||||
|
concurrencyConfig
|
||||||
|
}
|
||||||
|
|
||||||
type TemplateConfigProvider interface {
|
type TemplateConfigProvider interface {
|
||||||
Args() string
|
Args() string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/roboll/helmfile/pkg/argparser"
|
|
||||||
"github.com/roboll/helmfile/pkg/helmexec"
|
|
||||||
"github.com/roboll/helmfile/pkg/state"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/roboll/helmfile/pkg/argparser"
|
||||||
|
"github.com/roboll/helmfile/pkg/helmexec"
|
||||||
|
"github.com/roboll/helmfile/pkg/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Run struct {
|
type Run struct {
|
||||||
|
|
@ -49,13 +50,20 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create tmp directory and bail immediately if it fails
|
// Create tmp directory and bail immediately if it fails
|
||||||
dir, err := ioutil.TempDir("", "")
|
var dir string
|
||||||
if err != nil {
|
if len(opts.OutputDir) == 0 {
|
||||||
return err
|
tempDir, err := ioutil.TempDir("", "helmfile*")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
dir = tempDir
|
||||||
|
} else {
|
||||||
|
dir = opts.OutputDir
|
||||||
|
fmt.Printf("Charts will be downloaded to: %s\n", dir)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
if _, err = r.state.TriggerGlobalPrepareEvent(helmfileCommand); err != nil {
|
if _, err := r.state.TriggerGlobalPrepareEvent(helmfileCommand); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +90,7 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
|
||||||
|
|
||||||
f()
|
f()
|
||||||
|
|
||||||
_, err = r.state.TriggerGlobalCleanupEvent(helmfileCommand)
|
_, err := r.state.TriggerGlobalCleanupEvent(helmfileCommand)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -896,6 +896,7 @@ type ChartPrepareOptions struct {
|
||||||
SkipResolve bool
|
SkipResolve bool
|
||||||
Wait bool
|
Wait bool
|
||||||
WaitForJobs bool
|
WaitForJobs bool
|
||||||
|
OutputDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
type chartPrepareResult struct {
|
type chartPrepareResult struct {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateID(t *testing.T) {
|
func TestGenerateID(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue