Skip to content

Commit

Permalink
Added support for 'helm diff upgrade --install' (databus23#218)
Browse files Browse the repository at this point in the history
`--install` is now a valid alias to `--allow-unreleased`. `helm dif upgrade --install` behaves exactly the same as 'helm diff upgrade --allow-unreleased.

Ref databus23#108
  • Loading branch information
MFAshby authored Jul 20, 2020
1 parent 26d61fa commit e186caa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ type diffCmd struct {
outputContext int
showSecrets bool
postRenderer string
install bool
}

func (d *diffCmd) isAllowUnreleased() bool {
// helm update --install is effectively the same as helm-diff's --allow-unreleased option,
// support both so that helm diff plugin can be applied on the same command
// https://github.com/databus23/helm-diff/issues/108
return d.allowUnreleased || d.install
}

const globalUsage = `Show a diff explaining what a helm upgrade would change.
Expand Down Expand Up @@ -93,6 +101,7 @@ func newChartCommand() *cobra.Command {
f.BoolVar(&diff.reuseValues, "reuse-values", false, "reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored")
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.install, "install", false, "enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match \"helm upgrade --install\" command")
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.")
Expand Down Expand Up @@ -121,7 +130,7 @@ func (d *diffCmd) runHelm3() error {

var newInstall bool
if err != nil && strings.Contains(err.Error(), "release: not found") {
if d.allowUnreleased {
if d.isAllowUnreleased() {
fmt.Printf("********************\n\n\tRelease was not present in Helm. Diff will show entire contents as new.\n\n********************\n")
newInstall = true
err = nil
Expand Down Expand Up @@ -196,7 +205,7 @@ func (d *diffCmd) run() error {

var newInstall bool
if err != nil && strings.Contains(err.Error(), fmt.Sprintf("release: %q not found", d.release)) {
if d.allowUnreleased {
if d.isAllowUnreleased() {
fmt.Printf("********************\n\n\tRelease was not present in Helm. Diff will show entire contents as new.\n\n********************\n")
newInstall = true
err = nil
Expand Down

0 comments on commit e186caa

Please sign in to comment.