Skip to content

Commit eddde5a

Browse files
authored
Add support for --api-versions in helm-diff-upgrade (#329)
* Add support for --api-versions in helm-diff-upgrade Resolves #318 * Update helm-diff-upgrade usage in README
1 parent cd22d59 commit eddde5a

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

README.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,40 @@ Usage:
118118
Examples:
119119
helm diff upgrade my-release stable/postgresql --values values.yaml
120120
121+
# Set HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true to ignore unknown flags
122+
# It's useful when you're using `helm-diff` in a `helm upgrade` wrapper.
123+
HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm diff upgrade my-release stable/postgres --wait
124+
121125
Flags:
122-
-h, --help help for upgrade
123-
--detailed-exitcode return a non-zero exit code when there are changes
124-
--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
125-
--reset-values reset the values to the ones built into the chart and merge in any new values
126-
--reuse-values reuse the last release's values and merge in any new values
127-
--strip-trailing-cr strip trailing carriage return on input
128-
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
129-
--suppress stringArray allows suppression of the values listed in the diff output
130-
-q, --suppress-secrets suppress secrets in the output
131-
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
132-
--version string specify the exact chart version to use. If this is not specified, the latest version is used
126+
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
127+
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
128+
-C, --context int output NUM lines of context around changes (default -1)
129+
--detailed-exitcode return a non-zero exit code when there are changes
130+
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
131+
--disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema
132+
--disable-validation disables rendered templates validation against the Kubernetes cluster you are currently pointing to. This is the same validation performed on an install
133+
--dry-run disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation
134+
-h, --help help for upgrade
135+
--include-tests enable the diffing of the helm test hooks
136+
--install enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match "helm upgrade --install" command
137+
--kubeconfig string This flag is ignored, to allow passing of this top level flag to helm
138+
--no-hooks disable diffing of hooks
139+
--normalize-manifests normalize manifests before running diff to exclude style differences from the output
140+
--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")
141+
--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
142+
--repo string specify the chart repository url to locate the requested chart
143+
--reset-values reset the values to the ones built into the chart and merge in any new values
144+
--reuse-values reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored
145+
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
146+
--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)
147+
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
148+
--show-secrets do not redact secret values in the output
149+
--strip-trailing-cr strip trailing carriage return on input
150+
--suppress stringArray allows suppression of the values listed in the diff output
151+
-q, --suppress-secrets suppress secrets in the output
152+
--three-way-merge use three-way-merge to compute patch and generate diff output
153+
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
154+
--version string specify the exact chart version to use. If this is not specified, the latest version is used
133155
134156
Global Flags:
135157
--no-color remove colors from the output

cmd/helm3.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
141141
flags = append(flags, "--disable-openapi-validation")
142142
}
143143

144+
for _, a := range d.extraAPIs {
145+
flags = append(flags, "--api-versions", a)
146+
}
147+
144148
args := []string{"template", d.release, d.chart}
145149
args = append(args, flags...)
146150
cmd := exec.Command(os.Getenv("HELM_BIN"), args...)

cmd/upgrade.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type diffCmd struct {
6060
stripTrailingCR bool
6161
normalizeManifests bool
6262
threeWayMerge bool
63+
extraAPIs []string
6364
}
6465

6566
func (d *diffCmd) isAllowUnreleased() bool {
@@ -133,6 +134,10 @@ func newChartCommand() *cobra.Command {
133134
f.StringVar(&diff.chartVersion, "version", "", "specify the exact chart version to use. If this is not specified, the latest version is used")
134135
f.StringVar(&diff.chartRepo, "repo", "", "specify the chart repository url to locate the requested chart")
135136
f.BoolVar(&diff.detailedExitCode, "detailed-exitcode", false, "return a non-zero exit code when there are changes")
137+
// See the below links for more context on when to use this flag
138+
// - https://github.com/helm/helm/blob/d9ffe37d371c9d06448c55c852c800051830e49a/cmd/helm/template.go#L184
139+
// - https://github.com/databus23/helm-diff/issues/318
140+
f.StringArrayVarP(&diff.extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions")
136141
f.BoolP("suppress-secrets", "q", false, "suppress secrets in the output")
137142
f.BoolVar(&diff.showSecrets, "show-secrets", false, "do not redact secret values in the output")
138143
f.VarP(&diff.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)")

0 commit comments

Comments
 (0)