feat: add option `--include-tests` for diff and apply command (#1179)
Co-authored-by: Raymond Liu (RD-TW) <raymond_liu@trend.com.tw>
This commit is contained in:
parent
486be0970d
commit
71635caace
1
go.sum
1
go.sum
|
|
@ -562,6 +562,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
|
||||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
|
||||||
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.0/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.0/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -191,6 +191,10 @@ func main() {
|
||||||
Name: "detailed-exitcode",
|
Name: "detailed-exitcode",
|
||||||
Usage: "return a non-zero exit code when there are changes",
|
Usage: "return a non-zero exit code when there are changes",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "include-tests",
|
||||||
|
Usage: "enable the diffing of the helm test hooks",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "suppress-secrets",
|
Name: "suppress-secrets",
|
||||||
Usage: "suppress secrets in the output. highly recommended to specify on CI/CD use-cases",
|
Usage: "suppress secrets in the output. highly recommended to specify on CI/CD use-cases",
|
||||||
|
|
@ -346,6 +350,10 @@ func main() {
|
||||||
Name: "retain-values-files",
|
Name: "retain-values-files",
|
||||||
Usage: "Stop cleaning up values files passed to Helm. Together with --log-level=debug, you can manually rerun helm commands as Helmfile did for debugging purpose",
|
Usage: "Stop cleaning up values files passed to Helm. Together with --log-level=debug, you can manually rerun helm commands as Helmfile did for debugging purpose",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "include-tests",
|
||||||
|
Usage: "enable the diffing of the helm test hooks",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "suppress-secrets",
|
Name: "suppress-secrets",
|
||||||
Usage: "suppress secrets in the diff output. highly recommended to specify on CI/CD use-cases",
|
Usage: "suppress secrets in the diff output. highly recommended to specify on CI/CD use-cases",
|
||||||
|
|
@ -558,6 +566,10 @@ func (c configImpl) RetainValuesFiles() bool {
|
||||||
return c.c.Bool("retain-values-files")
|
return c.c.Bool("retain-values-files")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configImpl) IncludeTests() bool {
|
||||||
|
return c.c.Bool("include-tests")
|
||||||
|
}
|
||||||
|
|
||||||
func (c configImpl) SuppressSecrets() bool {
|
func (c configImpl) SuppressSecrets() bool {
|
||||||
return c.c.Bool("suppress-secrets")
|
return c.c.Bool("suppress-secrets")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -812,7 +812,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
|
||||||
|
|
||||||
// TODO Better way to detect diff on only filtered releases
|
// TODO Better way to detect diff on only filtered releases
|
||||||
{
|
{
|
||||||
changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), c.SuppressDiff(), false, diffOpts)
|
changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.IncludeTests(), c.SuppressSecrets(), c.SuppressDiff(), false, diffOpts)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
deletingReleases, err = st.DetectReleasesToBeDeletedForSync(helm, st.Releases)
|
deletingReleases, err = st.DetectReleasesToBeDeletedForSync(helm, st.Releases)
|
||||||
|
|
|
||||||
|
|
@ -2000,6 +2000,7 @@ type applyConfig struct {
|
||||||
set []string
|
set []string
|
||||||
validate bool
|
validate bool
|
||||||
skipDeps bool
|
skipDeps bool
|
||||||
|
includeTests bool
|
||||||
suppressSecrets bool
|
suppressSecrets bool
|
||||||
suppressDiff bool
|
suppressDiff bool
|
||||||
noColor bool
|
noColor bool
|
||||||
|
|
@ -2030,6 +2031,10 @@ func (a applyConfig) SkipDeps() bool {
|
||||||
return a.skipDeps
|
return a.skipDeps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a applyConfig) IncludeTests() bool {
|
||||||
|
return a.includeTests
|
||||||
|
}
|
||||||
|
|
||||||
func (a applyConfig) SuppressSecrets() bool {
|
func (a applyConfig) SuppressSecrets() bool {
|
||||||
return a.suppressSecrets
|
return a.suppressSecrets
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ type ApplyConfigProvider interface {
|
||||||
Set() []string
|
Set() []string
|
||||||
SkipDeps() bool
|
SkipDeps() bool
|
||||||
|
|
||||||
|
IncludeTests() bool
|
||||||
|
|
||||||
SuppressSecrets() bool
|
SuppressSecrets() bool
|
||||||
SuppressDiff() bool
|
SuppressDiff() bool
|
||||||
|
|
||||||
|
|
@ -73,6 +75,8 @@ type DiffConfigProvider interface {
|
||||||
Set() []string
|
Set() []string
|
||||||
SkipDeps() bool
|
SkipDeps() bool
|
||||||
|
|
||||||
|
IncludeTests() bool
|
||||||
|
|
||||||
SuppressSecrets() bool
|
SuppressSecrets() bool
|
||||||
SuppressDiff() bool
|
SuppressDiff() bool
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ func (r *Run) Diff(c DiffConfigProvider) []error {
|
||||||
NoColor: c.NoColor(),
|
NoColor: c.NoColor(),
|
||||||
Set: c.Set(),
|
Set: c.Set(),
|
||||||
}
|
}
|
||||||
_, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), c.DetailedExitcode(), c.SuppressSecrets(), c.SuppressDiff(), true, opts)
|
_, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), c.DetailedExitcode(), c.IncludeTests(), c.SuppressSecrets(), c.SuppressDiff(), true, opts)
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -951,7 +951,7 @@ type diffPrepareResult struct {
|
||||||
errors []*ReleaseError
|
errors []*ReleaseError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, suppressSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) {
|
func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, includeTests, suppressSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) {
|
||||||
opts := &DiffOpts{}
|
opts := &DiffOpts{}
|
||||||
for _, o := range opt {
|
for _, o := range opt {
|
||||||
o.Apply(opts)
|
o.Apply(opts)
|
||||||
|
|
@ -1014,6 +1014,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
|
||||||
flags = append(flags, "--detailed-exitcode")
|
flags = append(flags, "--detailed-exitcode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if includeTests {
|
||||||
|
flags = append(flags, "--include-tests")
|
||||||
|
}
|
||||||
|
|
||||||
if suppressSecrets {
|
if suppressSecrets {
|
||||||
flags = append(flags, "--suppress-secrets")
|
flags = append(flags, "--suppress-secrets")
|
||||||
}
|
}
|
||||||
|
|
@ -1099,13 +1103,13 @@ type DiffOpt interface{ Apply(*DiffOpts) }
|
||||||
|
|
||||||
// DiffReleases wrapper for executing helm diff on the releases
|
// DiffReleases wrapper for executing helm diff on the releases
|
||||||
// It returns releases that had any changes
|
// It returns releases that had any changes
|
||||||
func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, suppressSecrets bool, suppressDiff bool, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) {
|
func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, includeTests, suppressSecrets, suppressDiff, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) {
|
||||||
opts := &DiffOpts{}
|
opts := &DiffOpts{}
|
||||||
for _, o := range opt {
|
for _, o := range opt {
|
||||||
o.Apply(opts)
|
o.Apply(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, suppressSecrets, opts)
|
preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppressSecrets, opts)
|
||||||
if len(prepErrs) > 0 {
|
if len(prepErrs) > 0 {
|
||||||
return []ReleaseSpec{}, prepErrs
|
return []ReleaseSpec{}, prepErrs
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1391,7 +1391,7 @@ func TestHelmState_DiffReleases(t *testing.T) {
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
}
|
}
|
||||||
_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false)
|
_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false)
|
||||||
if errs != nil && len(errs) > 0 {
|
if errs != nil && len(errs) > 0 {
|
||||||
t.Errorf("unexpected error: %v", errs)
|
t.Errorf("unexpected error: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
@ -1556,7 +1556,7 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) {
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
state = injectFs(state, testfs)
|
state = injectFs(state, testfs)
|
||||||
if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false); errs != nil && len(errs) > 0 {
|
if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, false, false); errs != nil && len(errs) > 0 {
|
||||||
t.Errorf("unexpected errors: %v", errs)
|
t.Errorf("unexpected errors: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue