Skip to content

Commit e186caa

Browse files
authored
Added support for 'helm diff upgrade --install' (#218)
`--install` is now a valid alias to `--allow-unreleased`. `helm dif upgrade --install` behaves exactly the same as 'helm diff upgrade --allow-unreleased. Ref #108
1 parent 26d61fa commit e186caa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd/upgrade.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ type diffCmd struct {
3535
outputContext int
3636
showSecrets bool
3737
postRenderer string
38+
install bool
39+
}
40+
41+
func (d *diffCmd) isAllowUnreleased() bool {
42+
// helm update --install is effectively the same as helm-diff's --allow-unreleased option,
43+
// support both so that helm diff plugin can be applied on the same command
44+
// https://github.com/databus23/helm-diff/issues/108
45+
return d.allowUnreleased || d.install
3846
}
3947

4048
const globalUsage = `Show a diff explaining what a helm upgrade would change.
@@ -93,6 +101,7 @@ func newChartCommand() *cobra.Command {
93101
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")
94102
f.BoolVar(&diff.resetValues, "reset-values", false, "reset the values to the ones built into the chart and merge in any new values")
95103
f.BoolVar(&diff.allowUnreleased, "allow-unreleased", false, "enables diffing of releases that are not yet deployed via Helm")
104+
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")
96105
f.BoolVar(&diff.noHooks, "no-hooks", false, "disable diffing of hooks")
97106
f.BoolVar(&diff.includeTests, "include-tests", false, "enable the diffing of the helm test hooks")
98107
f.BoolVar(&diff.devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.")
@@ -121,7 +130,7 @@ func (d *diffCmd) runHelm3() error {
121130

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

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

0 commit comments

Comments
 (0)