Skip to content
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: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ Examples:

# Set HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true to ignore unknown flags
# It's useful when you're using `helm-diff` in a `helm upgrade` wrapper.
# See https://github.com/databus23/helm-diff/issues/278 for more information.
HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm diff upgrade my-release stable/postgres --wait

# Set HELM_DIFF_USE_UPGRADE_DRY_RUN=true to
# use `helm upgrade --dry-run` instead of `helm template` to render manifests from the chart.
# See https://github.com/databus23/helm-diff/issues/253 for more information.
HELM_DIFF_USE_UPGRADE_DRY_RUN=true helm diff upgarde my-release datadog/datadog

Flags:
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
Expand Down
62 changes: 50 additions & 12 deletions cmd/helm3.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -129,26 +130,63 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
flags = append(flags, "--set-file", fileValue)
}

if !d.disableValidation && !d.dryRun {
flags = append(flags, "--validate")
}

if isUpgrade {
flags = append(flags, "--is-upgrade")
}

if d.disableOpenAPIValidation {
flags = append(flags, "--disable-openapi-validation")
}

for _, a := range d.extraAPIs {
flags = append(flags, "--api-versions", a)
var (
subcmd string
filter func([]byte) []byte
)

if d.useUpgradeDryRun {
if d.dryRun {
return nil, fmt.Errorf("`diff upgrade --dry-run` conflicts with HELM_DIFF_USE_UPGRADE_DRY_RUN_AS_TEMPLATE. Either remove --dry-run to enable cluster access, or unset HELM_DIFF_USE_UPGRADE_DRY_RUN_AS_TEMPLATE to make cluster access unnecessary")
}

flags = append(flags, "--dry-run")
subcmd = "upgrade"
filter = func(s []byte) []byte {
if len(s) == 0 {
return s
}

i := bytes.Index(s, []byte("MANIFEST:"))
s = s[i:]
i = bytes.Index(s, []byte("---"))
s = s[i:]
i = bytes.Index(s, []byte("\nNOTES:"))
if i != -1 {
s = s[:i+1]
}
return s
}
} else {
if !d.disableValidation && !d.dryRun {
flags = append(flags, "--validate")
}

if isUpgrade {
flags = append(flags, "--is-upgrade")
}

for _, a := range d.extraAPIs {
flags = append(flags, "--api-versions", a)
}

subcmd = "template"

filter = func(s []byte) []byte {
return s
}
}

args := []string{"template", d.release, d.chart}
args := []string{subcmd, d.release, d.chart}
args = append(args, flags...)

cmd := exec.Command(os.Getenv("HELM_BIN"), args...)
return outputWithRichError(cmd)
out, err := outputWithRichError(cmd)
return filter(out), err
}

func (d *diffCmd) writeExistingValues(f *os.File) error {
Expand Down
10 changes: 10 additions & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type diffCmd struct {
normalizeManifests bool
threeWayMerge bool
extraAPIs []string
useUpgradeDryRun bool
}

func (d *diffCmd) isAllowUnreleased() bool {
Expand Down Expand Up @@ -95,7 +96,13 @@ func newChartCommand() *cobra.Command {
"",
" # Set HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true to ignore unknown flags",
" # It's useful when you're using `helm-diff` in a `helm upgrade` wrapper.",
" # See https://github.com/databus23/helm-diff/issues/278 for more information.",
" HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm diff upgrade my-release stable/postgres --wait",
"",
" # Set HELM_DIFF_USE_UPGRADE_DRY_RUN=true to ",
" # use `helm upgrade --dry-run` instead of `helm template` to render manifests from the chart.",
" # See https://github.com/databus23/helm-diff/issues/253 for more information.",
" HELM_DIFF_USE_UPGRADE_DRY_RUN=true helm diff upgarde my-release datadog/datadog",
}, "\n"),
Args: func(cmd *cobra.Command, args []string) error {
return checkArgsLength(len(args), "release name", "chart path")
Expand All @@ -107,6 +114,9 @@ func newChartCommand() *cobra.Command {
// Suppress the command usage on error. See #77 for more info
cmd.SilenceUsage = true

// See https://github.com/databus23/helm-diff/issues/253
diff.useUpgradeDryRun = os.Getenv("HELM_DIFF_USE_UPGRADE_DRY_RUN") == "true"

if q, _ := cmd.Flags().GetBool("suppress-secrets"); q {
diff.suppressedKinds = append(diff.suppressedKinds, "Secret")
}
Expand Down