Skip to content

Disable diffing against test hooks by default #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type diffCmd struct {
resetValues bool
allowUnreleased bool
noHooks bool
includeTests bool
suppressedKinds []string
outputContext int
}
Expand Down Expand Up @@ -84,6 +85,7 @@ func newChartCommand() *cobra.Command {
f.BoolVar(&diff.resetValues, "reset-values", false, "reset the values to the ones built into the chart and merge in any new values")
f.BoolVar(&diff.allowUnreleased, "allow-unreleased", false, "enables diffing of releases that are not yet deployed via Helm")
f.BoolVar(&diff.noHooks, "no-hooks", false, "disable diffing of hooks")
f.BoolVar(&diff.includeTests, "include-tests", false, "enable the diffing of the helm test hooks")
f.BoolVar(&diff.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.")
f.StringArrayVar(&diff.suppressedKinds, "suppress", []string{}, "allows suppression of the values listed in the diff output")
f.IntVarP(&diff.outputContext, "context", "C", -1, "output NUM lines of context around changes")
Expand Down Expand Up @@ -164,8 +166,8 @@ func (d *diffCmd) run() error {
currentSpecs = manifest.Parse(releaseResponse.Release.Manifest, releaseResponse.Release.Namespace)
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest, upgradeResponse.Release.Namespace)
} else {
currentSpecs = manifest.ParseRelease(releaseResponse.Release)
newSpecs = manifest.ParseRelease(upgradeResponse.Release)
currentSpecs = manifest.ParseRelease(releaseResponse.Release, d.includeTests)
newSpecs = manifest.ParseRelease(upgradeResponse.Release, d.includeTests)
}
}

Expand Down
15 changes: 14 additions & 1 deletion manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ func splitSpec(token string) (string, string) {
return "", ""
}

func ParseRelease(release *release.Release) map[string]*MappingResult {
func ParseRelease(release *release.Release, includeTests bool) map[string]*MappingResult {
manifest := release.Manifest
for _, hook := range release.Hooks {
if !includeTests && isTestHook(hook.Events) {
continue
}

manifest += "\n---\n"
manifest += fmt.Sprintf("# Source: %s\n", hook.Path)
manifest += hook.Manifest
Expand Down Expand Up @@ -105,5 +109,14 @@ func Parse(manifest string, defaultNamespace string) map[string]*MappingResult {
}
}
return result
}

func isTestHook(hookEvents []release.Hook_Event) bool {
for _, event := range hookEvents {
if event == release.Hook_RELEASE_TEST_FAILURE || event == release.Hook_RELEASE_TEST_SUCCESS {
return true
}
}

return false
}