Skip to content

New chart diffing #15

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 1 commit into from
Jun 1, 2018
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
57 changes: 45 additions & 12 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"fmt"
"os"
"strings"

"github.com/databus23/helm-diff/diff"
"github.com/databus23/helm-diff/manifest"
Expand All @@ -18,6 +20,7 @@ type diffCmd struct {
values []string
reuseValues bool
resetValues bool
allowUnreleased bool
suppressedKinds []string
}

Expand Down Expand Up @@ -62,6 +65,7 @@ func newChartCommand() *cobra.Command {
f.StringArrayVar(&diff.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.BoolVar(&diff.reuseValues, "reuse-values", false, "reuse the last release's values and merge in any new values")
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.StringArrayVar(&diff.suppressedKinds, "suppress", []string{}, "allows suppression of the values listed in the diff output")

return cmd
Expand All @@ -85,24 +89,53 @@ func (d *diffCmd) run() error {

releaseResponse, err := d.client.ReleaseContent(d.release)

if err != nil {
return prettyError(err)
var newInstall bool
if err != nil && strings.Contains(err.Error(), fmt.Sprintf("release: %q not found", d.release)) {
if d.allowUnreleased {
fmt.Printf("********************\n\n\tRelease was not present in Helm. Diff will show entire contents as new.\n\n********************\n")
newInstall = true
err = nil
} else {
fmt.Printf("********************\n\n\tRelease was not present in Helm. Include the `--allow-unreleased` to perform diff without exiting in error.\n\n********************\n")
}

}

upgradeResponse, err := d.client.UpdateRelease(
d.release,
chartPath,
helm.UpdateValueOverrides(rawVals),
helm.ReuseValues(d.reuseValues),
helm.ResetValues(d.resetValues),
helm.UpgradeDryRun(true),
)
if err != nil {
return prettyError(err)
}

currentSpecs := manifest.Parse(releaseResponse.Release.Manifest)
newSpecs := manifest.Parse(upgradeResponse.Release.Manifest)
var currentSpecs, newSpecs map[string]*manifest.MappingResult
if newInstall {
installResponse, err := d.client.InstallRelease(
chartPath,
"default",
helm.ReleaseName(d.release),
helm.ValueOverrides(rawVals),
helm.InstallDryRun(true),
)
if err != nil {
return prettyError(err)
}

currentSpecs = make(map[string]*manifest.MappingResult)
newSpecs = manifest.Parse(installResponse.Release.Manifest)
} else {
upgradeResponse, err := d.client.UpdateRelease(
d.release,
chartPath,
helm.UpdateValueOverrides(rawVals),
helm.ReuseValues(d.reuseValues),
helm.ResetValues(d.resetValues),
helm.UpgradeDryRun(true),
)
if err != nil {
return prettyError(err)
}

currentSpecs = manifest.Parse(releaseResponse.Release.Manifest)
newSpecs = manifest.Parse(upgradeResponse.Release.Manifest)
}

diff.DiffManifests(currentSpecs, newSpecs, d.suppressedKinds, os.Stdout)

Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func main() {

if err := cmd.New().Execute(); err != nil {
os.Exit(1)
}
Expand Down