feat(diff,apply): --context=N for limiting diff context (#849)

Resolves #787
This commit is contained in:
KUOKA Yusuke 2019-09-12 18:36:13 +09:00 committed by GitHub
parent fb2041555e
commit 94a6fcfb9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

14
main.go
View File

@ -187,6 +187,11 @@ func main() {
Value: 0,
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 {
return run.Diff(c)
@ -290,6 +295,11 @@ func main() {
Value: 0,
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{
Name: "args",
Value: "",
@ -545,6 +555,10 @@ func (c configImpl) NoColor() bool {
return c.c.GlobalBool("no-color")
}
func (c configImpl) Context() int {
return c.c.Int("context")
}
func (c configImpl) Logger() *zap.SugaredLogger {
return c.c.App.Metadata["logger"].(*zap.SugaredLogger)
}

View File

@ -41,6 +41,7 @@ type ApplyConfigProvider interface {
SuppressSecrets() bool
NoColor() bool
Context() int
concurrencyConfig
interactive
@ -67,6 +68,7 @@ type DiffConfigProvider interface {
DetailedExitcode() bool
NoColor() bool
Context() int
concurrencyConfig
}

View File

@ -139,6 +139,7 @@ func (r *Run) Apply(c ApplyConfigProvider) []error {
diffOpts := &state.DiffOpts{
NoColor: c.NoColor(),
Context: c.Context(),
}
releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false, diffOpts)

View File

@ -776,6 +776,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
flags = append(flags, "--no-color")
}
if opts.Context > 0 {
flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context))
}
if len(errs) > 0 {
rsErrs := make([]*ReleaseError, len(errs))
for i, e := range errs {
@ -823,6 +827,7 @@ func (st *HelmState) createHelmContext(spec *ReleaseSpec, workerIndex int) helme
type DiffOpts struct {
NoColor bool
Context int
}
func (o *DiffOpts) Apply(opts *DiffOpts) {

View File

@ -63,6 +63,9 @@ bash -c "${helmfile} -f ${dir}/happypath.yaml diff --detailed-exitcode; code="'$
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"
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"
${helmfile} -f ${dir}/happypath.yaml template
code=$?