-
Notifications
You must be signed in to change notification settings - Fork 292
feature: diffing between different releases #131
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/helm/pkg/helm" | ||
|
||
"github.com/databus23/helm-diff/diff" | ||
"github.com/databus23/helm-diff/manifest" | ||
) | ||
|
||
type release struct { | ||
client helm.Interface | ||
detailedExitCode bool | ||
suppressedKinds []string | ||
releases []string | ||
outputContext int | ||
includeTests bool | ||
} | ||
|
||
const releaseCmdLongUsage = ` | ||
This command compares the manifests details of a different releases created from the same chart | ||
|
||
It can be used to compare the manifests of | ||
|
||
- release1 with release2 | ||
$ helm diff release [flags] release1 release2 | ||
Example: | ||
$ helm diff release my-prod my-stage | ||
` | ||
|
||
func releaseCmd() *cobra.Command { | ||
diff := release{} | ||
releaseCmd := &cobra.Command{ | ||
Use: "release [flags] RELEASE release1 [release2]", | ||
Short: "Shows diff between release's manifests", | ||
Long: releaseCmdLongUsage, | ||
PreRun: func(*cobra.Command, []string) { | ||
expandTLSPaths() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// Suppress the command usage on error. See #77 for more info | ||
cmd.SilenceUsage = true | ||
|
||
if v, _ := cmd.Flags().GetBool("version"); v { | ||
fmt.Println(Version) | ||
return nil | ||
} | ||
|
||
switch { | ||
case len(args) < 2: | ||
return errors.New("Too few arguments to Command \"release\".\nMinimum 2 arguments required: release name-1, release name-2") | ||
} | ||
|
||
if q, _ := cmd.Flags().GetBool("suppress-secrets"); q { | ||
diff.suppressedKinds = append(diff.suppressedKinds, "Secret") | ||
} | ||
|
||
diff.releases = args[0:] | ||
if diff.client == nil { | ||
diff.client = createHelmClient() | ||
} | ||
return diff.differentiate() | ||
}, | ||
} | ||
|
||
releaseCmd.Flags().BoolP("suppress-secrets", "q", false, "suppress secrets in the output") | ||
releaseCmd.Flags().StringArrayVar(&diff.suppressedKinds, "suppress", []string{}, "allows suppression of the values listed in the diff output") | ||
releaseCmd.Flags().IntVarP(&diff.outputContext, "context", "C", -1, "output NUM lines of context around changes") | ||
releaseCmd.Flags().BoolVar(&diff.includeTests, "include-tests", false, "enable the diffing of the helm test hooks") | ||
releaseCmd.SuggestionsMinimumDistance = 1 | ||
|
||
addCommonCmdOptions(releaseCmd.Flags()) | ||
|
||
return releaseCmd | ||
} | ||
|
||
func (d *release) differentiate() error { | ||
|
||
releaseResponse1, err := d.client.ReleaseContent(d.releases[0]) | ||
if err != nil { | ||
return prettyError(err) | ||
} | ||
|
||
releaseResponse2, err := d.client.ReleaseContent(d.releases[1]) | ||
if err != nil { | ||
return prettyError(err) | ||
} | ||
|
||
if releaseResponse1.Release.Chart.Metadata.Name == releaseResponse2.Release.Chart.Metadata.Name { | ||
seenAnyChanges := diff.DiffReleases( | ||
manifest.ParseRelease(releaseResponse1.Release, d.includeTests), | ||
manifest.ParseRelease(releaseResponse2.Release, d.includeTests), | ||
d.suppressedKinds, | ||
d.outputContext, | ||
os.Stdout) | ||
|
||
if d.detailedExitCode && seenAnyChanges { | ||
return Error{ | ||
error: errors.New("identified at least one change, exiting with non-zero exit code (detailed-exitcode parameter enabled)"), | ||
Code: 2, | ||
} | ||
} | ||
} else { | ||
fmt.Printf("Error : Incomparable Releases \n Unable to compare releases from two different charts \"%s\", \"%s\". \n try helm diff release --help to know more \n", releaseResponse1.Release.Chart.Metadata.Name, releaseResponse2.Release.Chart.Metadata.Name) | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very nit but I think it's fine to say
reindex
rather thanreIndex
😃