feat(diff,apply): --context=N for limiting diff context (#849)
Resolves #787
This commit is contained in:
		
							parent
							
								
									fb2041555e
								
							
						
					
					
						commit
						94a6fcfb9f
					
				
							
								
								
									
										14
									
								
								main.go
								
								
								
								
							
							
						
						
									
										14
									
								
								main.go
								
								
								
								
							|  | @ -187,6 +187,11 @@ func main() { | ||||||
| 					Value: 0, | 					Value: 0, | ||||||
| 					Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", | 					Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", | ||||||
| 				}, | 				}, | ||||||
|  | 				cli.IntFlag{ | ||||||
|  | 					Name:  "context", | ||||||
|  | 					Value: 0, | ||||||
|  | 					Usage: "output NUM lines of context around changes", | ||||||
|  | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Action: action(func(run *app.App, c configImpl) error { | 			Action: action(func(run *app.App, c configImpl) error { | ||||||
| 				return run.Diff(c) | 				return run.Diff(c) | ||||||
|  | @ -290,6 +295,11 @@ func main() { | ||||||
| 					Value: 0, | 					Value: 0, | ||||||
| 					Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", | 					Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", | ||||||
| 				}, | 				}, | ||||||
|  | 				cli.IntFlag{ | ||||||
|  | 					Name:  "context", | ||||||
|  | 					Value: 0, | ||||||
|  | 					Usage: "output NUM lines of context around changes", | ||||||
|  | 				}, | ||||||
| 				cli.StringFlag{ | 				cli.StringFlag{ | ||||||
| 					Name:  "args", | 					Name:  "args", | ||||||
| 					Value: "", | 					Value: "", | ||||||
|  | @ -545,6 +555,10 @@ func (c configImpl) NoColor() bool { | ||||||
| 	return c.c.GlobalBool("no-color") | 	return c.c.GlobalBool("no-color") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (c configImpl) Context() int { | ||||||
|  | 	return c.c.Int("context") | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (c configImpl) Logger() *zap.SugaredLogger { | func (c configImpl) Logger() *zap.SugaredLogger { | ||||||
| 	return c.c.App.Metadata["logger"].(*zap.SugaredLogger) | 	return c.c.App.Metadata["logger"].(*zap.SugaredLogger) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -41,6 +41,7 @@ type ApplyConfigProvider interface { | ||||||
| 	SuppressSecrets() bool | 	SuppressSecrets() bool | ||||||
| 
 | 
 | ||||||
| 	NoColor() bool | 	NoColor() bool | ||||||
|  | 	Context() int | ||||||
| 
 | 
 | ||||||
| 	concurrencyConfig | 	concurrencyConfig | ||||||
| 	interactive | 	interactive | ||||||
|  | @ -67,6 +68,7 @@ type DiffConfigProvider interface { | ||||||
| 
 | 
 | ||||||
| 	DetailedExitcode() bool | 	DetailedExitcode() bool | ||||||
| 	NoColor() bool | 	NoColor() bool | ||||||
|  | 	Context() int | ||||||
| 
 | 
 | ||||||
| 	concurrencyConfig | 	concurrencyConfig | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -139,6 +139,7 @@ func (r *Run) Apply(c ApplyConfigProvider) []error { | ||||||
| 
 | 
 | ||||||
| 	diffOpts := &state.DiffOpts{ | 	diffOpts := &state.DiffOpts{ | ||||||
| 		NoColor: c.NoColor(), | 		NoColor: c.NoColor(), | ||||||
|  | 		Context: c.Context(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false, diffOpts) | 	releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false, diffOpts) | ||||||
|  |  | ||||||
|  | @ -776,6 +776,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu | ||||||
| 					flags = append(flags, "--no-color") | 					flags = append(flags, "--no-color") | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | 				if opts.Context > 0 { | ||||||
|  | 					flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context)) | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
| 				if len(errs) > 0 { | 				if len(errs) > 0 { | ||||||
| 					rsErrs := make([]*ReleaseError, len(errs)) | 					rsErrs := make([]*ReleaseError, len(errs)) | ||||||
| 					for i, e := range errs { | 					for i, e := range errs { | ||||||
|  | @ -823,6 +827,7 @@ func (st *HelmState) createHelmContext(spec *ReleaseSpec, workerIndex int) helme | ||||||
| 
 | 
 | ||||||
| type DiffOpts struct { | type DiffOpts struct { | ||||||
| 	NoColor bool | 	NoColor bool | ||||||
|  | 	Context int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (o *DiffOpts) Apply(opts *DiffOpts) { | func (o *DiffOpts) Apply(opts *DiffOpts) { | ||||||
|  |  | ||||||
|  | @ -63,6 +63,9 @@ bash -c "${helmfile} -f ${dir}/happypath.yaml diff --detailed-exitcode; code="'$ | ||||||
| info "Diffing ${dir}/happypath.yaml without color" | info "Diffing ${dir}/happypath.yaml without color" | ||||||
| bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" | bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" | ||||||
| 
 | 
 | ||||||
|  | info "Diffing ${dir}/happypath.yaml with limited context" | ||||||
|  | bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" | ||||||
|  | 
 | ||||||
| info "Templating ${dir}/happypath.yaml" | info "Templating ${dir}/happypath.yaml" | ||||||
| ${helmfile} -f ${dir}/happypath.yaml template | ${helmfile} -f ${dir}/happypath.yaml template | ||||||
| code=$? | code=$? | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue