feat: Add `helmfile test --logs` (#1569)

When `--logs` is provided, Helmfile runs `helm test --logs` so that it can stream test logs

Ref #1541
This commit is contained in:
Yusuke Kuoka 2020-11-05 10:17:18 +09:00 committed by GitHub
parent 6b86408500
commit 3899680672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 2 deletions

View File

@ -478,6 +478,10 @@ func main() {
Name: "cleanup",
Usage: "delete test pods upon completion",
},
cli.BoolFlag{
Name: "logs",
Usage: "Dump the logs from test pods (this runs after all tests are complete, but before any cleanup)",
},
cli.StringFlag{
Name: "args",
Value: "",
@ -662,6 +666,10 @@ func (c configImpl) Cleanup() bool {
return c.c.Bool("cleanup")
}
func (c configImpl) Logs() bool {
return c.c.Bool("logs")
}
func (c configImpl) Timeout() int {
if !c.c.IsSet("timeout") {
return state.EmptyTimeout

View File

@ -110,6 +110,7 @@ type TestConfigProvider interface {
Timeout() int
Cleanup() bool
Logs() bool
concurrencyConfig
}

View File

@ -183,7 +183,7 @@ func (a *App) test(r *Run, c TestConfigProvider) []error {
r.helm.SetExtraArgs(argparser.GetArgs(c.Args(), r.state)...)
return st.TestReleases(r.helm, cleanup, timeout, concurrency)
return st.TestReleases(r.helm, cleanup, timeout, concurrency, state.Logs(c.Logs()))
}
func (r *Run) Lint(c LintConfigProvider) []error {

View File

@ -1686,8 +1686,26 @@ func (st *HelmState) DeleteReleases(affectedReleases *AffectedReleases, helm hel
})
}
type TestOpts struct {
Logs bool
}
type TestOption func(*TestOpts)
func Logs(v bool) func(*TestOpts) {
return func(o *TestOpts) {
o.Logs = v
}
}
// TestReleases wrapper for executing helm test on the releases
func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout int, concurrency int) []error {
func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout int, concurrency int, options ...TestOption) []error {
var opts TestOpts
for _, o := range options {
o(&opts)
}
return st.scatterGatherReleases(helm, concurrency, func(release ReleaseSpec, workerIndex int) error {
if !release.Desired() {
return nil
@ -1700,6 +1718,9 @@ func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout
if cleanup && !helm.IsHelm3() {
flags = append(flags, "--cleanup")
}
if opts.Logs {
flags = append(flags, "--logs")
}
if timeout == EmptyTimeout {
flags = append(flags, st.timeoutFlags(helm, &release)...)