From e0f38c610d5803d40a92c241b0d8c67bbf05e860 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sun, 9 Jan 2022 03:41:55 +0000 Subject: [PATCH 1/2] Add support for --api-versions in helm-diff-upgrade Resolves #318 --- cmd/helm3.go | 4 ++++ cmd/upgrade.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/cmd/helm3.go b/cmd/helm3.go index 5188e840..2adb7386 100644 --- a/cmd/helm3.go +++ b/cmd/helm3.go @@ -141,6 +141,10 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) { flags = append(flags, "--disable-openapi-validation") } + for _, a := range d.extraAPIs { + flags = append(flags, "--api-versions", a) + } + args := []string{"template", d.release, d.chart} args = append(args, flags...) cmd := exec.Command(os.Getenv("HELM_BIN"), args...) diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 136a7451..98e1303a 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -60,6 +60,7 @@ type diffCmd struct { stripTrailingCR bool normalizeManifests bool threeWayMerge bool + extraAPIs []string } func (d *diffCmd) isAllowUnreleased() bool { @@ -133,6 +134,10 @@ func newChartCommand() *cobra.Command { f.StringVar(&diff.chartVersion, "version", "", "specify the exact chart version to use. If this is not specified, the latest version is used") f.StringVar(&diff.chartRepo, "repo", "", "specify the chart repository url to locate the requested chart") f.BoolVar(&diff.detailedExitCode, "detailed-exitcode", false, "return a non-zero exit code when there are changes") + // See the below links for more context on when to use this flag + // - https://github.com/helm/helm/blob/d9ffe37d371c9d06448c55c852c800051830e49a/cmd/helm/template.go#L184 + // - https://github.com/databus23/helm-diff/issues/318 + f.StringArrayVarP(&diff.extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions") f.BoolP("suppress-secrets", "q", false, "suppress secrets in the output") f.BoolVar(&diff.showSecrets, "show-secrets", false, "do not redact secret values in the output") f.VarP(&diff.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)") From 7e167d656fc469be6612c5d152ba3d0b693c7cd7 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sun, 9 Jan 2022 03:43:46 +0000 Subject: [PATCH 2/2] Update helm-diff-upgrade usage in README --- README.md | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 55a58e3a..ab24fbaa 100644 --- a/README.md +++ b/README.md @@ -118,18 +118,40 @@ Usage: Examples: helm diff upgrade my-release stable/postgresql --values values.yaml + # 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. + HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm diff upgrade my-release stable/postgres --wait + Flags: - -h, --help help for upgrade - --detailed-exitcode return a non-zero exit code when there are changes - --post-renderer string the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path - --reset-values reset the values to the ones built into the chart and merge in any new values - --reuse-values reuse the last release's values and merge in any new values - --strip-trailing-cr strip trailing carriage return on input - --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) - --suppress stringArray allows suppression of the values listed in the diff output - -q, --suppress-secrets suppress secrets in the output - -f, --values valueFiles specify values in a YAML file (can specify multiple) (default []) - --version string specify the exact chart version to use. If this is not specified, the latest version is used + --allow-unreleased enables diffing of releases that are not yet deployed via Helm + -a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions + -C, --context int output NUM lines of context around changes (default -1) + --detailed-exitcode return a non-zero exit code when there are changes + --devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored. + --disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema + --disable-validation disables rendered templates validation against the Kubernetes cluster you are currently pointing to. This is the same validation performed on an install + --dry-run disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation + -h, --help help for upgrade + --include-tests enable the diffing of the helm test hooks + --install enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match "helm upgrade --install" command + --kubeconfig string This flag is ignored, to allow passing of this top level flag to helm + --no-hooks disable diffing of hooks + --normalize-manifests normalize manifests before running diff to exclude style differences from the output + --output string Possible values: diff, simple, json, template. When set to "template", use the env var HELM_DIFF_TPL to specify the template. (default "diff") + --post-renderer string the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path + --repo string specify the chart repository url to locate the requested chart + --reset-values reset the values to the ones built into the chart and merge in any new values + --reuse-values reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored + --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) + --set-file stringArray set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2) + --set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) + --show-secrets do not redact secret values in the output + --strip-trailing-cr strip trailing carriage return on input + --suppress stringArray allows suppression of the values listed in the diff output + -q, --suppress-secrets suppress secrets in the output + --three-way-merge use three-way-merge to compute patch and generate diff output + -f, --values valueFiles specify values in a YAML file (can specify multiple) (default []) + --version string specify the exact chart version to use. If this is not specified, the latest version is used Global Flags: --no-color remove colors from the output