diff --git a/main.go b/main.go index 7fd386c6..f84acf44 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/pkg/app/config.go b/pkg/app/config.go index 5cc1d173..484ee606 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -110,6 +110,7 @@ type TestConfigProvider interface { Timeout() int Cleanup() bool + Logs() bool concurrencyConfig } diff --git a/pkg/app/run.go b/pkg/app/run.go index df8e2cf5..56cfebe5 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -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 { diff --git a/pkg/state/state.go b/pkg/state/state.go index 00f28c38..8a655bc8 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -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)...)