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:
		
							parent
							
								
									6b86408500
								
							
						
					
					
						commit
						3899680672
					
				
							
								
								
									
										8
									
								
								main.go
								
								
								
								
							
							
						
						
									
										8
									
								
								main.go
								
								
								
								
							|  | @ -478,6 +478,10 @@ func main() { | ||||||
| 					Name:  "cleanup", | 					Name:  "cleanup", | ||||||
| 					Usage: "delete test pods upon completion", | 					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{ | 				cli.StringFlag{ | ||||||
| 					Name:  "args", | 					Name:  "args", | ||||||
| 					Value: "", | 					Value: "", | ||||||
|  | @ -662,6 +666,10 @@ func (c configImpl) Cleanup() bool { | ||||||
| 	return c.c.Bool("cleanup") | 	return c.c.Bool("cleanup") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (c configImpl) Logs() bool { | ||||||
|  | 	return c.c.Bool("logs") | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (c configImpl) Timeout() int { | func (c configImpl) Timeout() int { | ||||||
| 	if !c.c.IsSet("timeout") { | 	if !c.c.IsSet("timeout") { | ||||||
| 		return state.EmptyTimeout | 		return state.EmptyTimeout | ||||||
|  |  | ||||||
|  | @ -110,6 +110,7 @@ type TestConfigProvider interface { | ||||||
| 
 | 
 | ||||||
| 	Timeout() int | 	Timeout() int | ||||||
| 	Cleanup() bool | 	Cleanup() bool | ||||||
|  | 	Logs() bool | ||||||
| 
 | 
 | ||||||
| 	concurrencyConfig | 	concurrencyConfig | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -183,7 +183,7 @@ func (a *App) test(r *Run, c TestConfigProvider) []error { | ||||||
| 
 | 
 | ||||||
| 	r.helm.SetExtraArgs(argparser.GetArgs(c.Args(), r.state)...) | 	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 { | func (r *Run) Lint(c LintConfigProvider) []error { | ||||||
|  |  | ||||||
|  | @ -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
 | // 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 { | 	return st.scatterGatherReleases(helm, concurrency, func(release ReleaseSpec, workerIndex int) error { | ||||||
| 		if !release.Desired() { | 		if !release.Desired() { | ||||||
| 			return nil | 			return nil | ||||||
|  | @ -1700,6 +1718,9 @@ func (st *HelmState) TestReleases(helm helmexec.Interface, cleanup bool, timeout | ||||||
| 		if cleanup && !helm.IsHelm3() { | 		if cleanup && !helm.IsHelm3() { | ||||||
| 			flags = append(flags, "--cleanup") | 			flags = append(flags, "--cleanup") | ||||||
| 		} | 		} | ||||||
|  | 		if opts.Logs { | ||||||
|  | 			flags = append(flags, "--logs") | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		if timeout == EmptyTimeout { | 		if timeout == EmptyTimeout { | ||||||
| 			flags = append(flags, st.timeoutFlags(helm, &release)...) | 			flags = append(flags, st.timeoutFlags(helm, &release)...) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue