From e7abc92a772e142c759a4cc4349bed8af9a12f45 Mon Sep 17 00:00:00 2001 From: Daniel Lenar Date: Wed, 14 Dec 2022 00:18:00 -0600 Subject: [PATCH] Add post-renderer-args flag Signed-off-by: Daniel Lenar --- README.md | 150 +++++++++++++++++++++++++------------------------ cmd/helm3.go | 3 + cmd/upgrade.go | 2 + 3 files changed, 83 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 901e14eb..d6a3464b 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Usage: diff [command] Available Commands: + completion Generate the autocompletion script for the specified shell release Shows diff between release's manifests revision Shows diff between revision's manifests rollback Show a diff explaining what a helm rollback could perform @@ -83,38 +84,40 @@ Available Commands: version Show version of the helm diff plugin 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 - --color color output. You can control the value for this flag via HELM_DIFF_COLOR=[true|false]. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" - -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 diff - --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 - --kube-version string Kubernetes version used for Capabilities.KubeVersion - --kubeconfig string This flag is ignored, to allow passing of this top level flag to helm - --no-color remove colors from the output. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" - --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 + --allow-unreleased enables diffing of releases that are not yet deployed via Helm + -a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions + --color color output. You can control the value for this flag via HELM_DIFF_COLOR=[true|false]. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" + -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 + -D, --find-renames float32 Enable rename detection if set to any value greater than 0. If specified, the value denotes the maximum fraction of changed content as lines added + removed compared to total lines in a diff for considering it a rename. Only objects of the same Kind are attempted to be matched + -h, --help help for diff + --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 + --kube-version string Kubernetes version used for Capabilities.KubeVersion + --kubeconfig string This flag is ignored, to allow passing of this top level flag to helm + --no-color remove colors from the output. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" + --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, 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 + --post-renderer-args stringArray an argument to the post-renderer (can specify multiple) + --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 Additional help topics: diff @@ -157,51 +160,54 @@ Examples: # Read the flag usage below for more information on --three-way-merge. HELM_DIFF_THREE_WAY_MERGE=true helm diff upgrade my-release datadog/datadog - # Set HELM_DIFF_NORMALIZE_MANIFESTS=true to", - # normalize the yaml file content when using helm diff.", - # This is equivalent to specifying the --normalize-manifests flag.", - # Read the flag usage below for more information on --normalize-manifests.", - HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog", + # Set HELM_DIFF_NORMALIZE_MANIFESTS=true to + # normalize the yaml file content when using helm diff. + # This is equivalent to specifying the --normalize-manifests flag. + # Read the flag usage below for more information on --normalize-manifests. + HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog - # Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines. - # This is equivalent to specifying the --context flag. - # Read the flag usage below for more information on --context. - HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade my-release datadog/datadog +# Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines. +# This is equivalent to specifying the --context flag. +# Read the flag usage below for more information on --context. +HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade 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 - -C, --context int output NUM lines of context around changes (default -1), or use HELM_DIFF_OUTPUT_CONTEXT=num - --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 - --kube-version string Kubernetes version used for Capabilities.KubeVersion - --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, or use HELM_DIFF_NORMALIZE_MANIFESTS=true. - --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, or use HELM_DIFF_THREE_WAY_MERGE=true. - -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 + -D, --find-renames float32 Enable rename detection if set to any value greater than 0. If specified, the value denotes the maximum fraction of changed content as lines added + removed compared to total lines in a diff for considering it a rename. Only objects of the same Kind are attempted to be matched + -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 + --kube-version string Kubernetes version used for Capabilities.KubeVersion + --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, 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 + --post-renderer-args stringArray an argument to the post-renderer (can specify multiple) + --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 + --color color output. You can control the value for this flag via HELM_DIFF_COLOR=[true|false]. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" + --no-color remove colors from the output. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb" ``` ### release: diff --git a/cmd/helm3.go b/cmd/helm3.go index 0dfc4332..b19b2b20 100644 --- a/cmd/helm3.go +++ b/cmd/helm3.go @@ -102,6 +102,9 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) { if d.postRenderer != "" { flags = append(flags, "--post-renderer", d.postRenderer) } + for _, arg := range d.postRendererArgs { + flags = append(flags, "--post-renderer-args", arg) + } // Helm automatically enable --reuse-values when there's no --set, --set-string, --set-values, --set-file present. // Let's simulate that in helm-diff. // See https://medium.com/@kcatstack/understand-helm-upgrade-flags-reset-values-reuse-values-6e58ac8f127e diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 62e564a9..be39505f 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -53,6 +53,7 @@ type diffCmd struct { noHooks bool includeTests bool postRenderer string + postRendererArgs []string install bool normalizeManifests bool threeWayMerge bool @@ -206,6 +207,7 @@ func newChartCommand() *cobra.Command { f.BoolVar(&diff.disableOpenAPIValidation, "disable-openapi-validation", false, "disables rendered templates validation against the Kubernetes OpenAPI Schema") f.BoolVar(&diff.dryRun, "dry-run", false, "disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation") f.StringVar(&diff.postRenderer, "post-renderer", "", "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") + f.StringArrayVar(&diff.postRendererArgs, "post-renderer-args", []string{}, "an argument to the post-renderer (can specify multiple)") f.BoolVar(&diff.normalizeManifests, "normalize-manifests", false, "normalize manifests before running diff to exclude style differences from the output") AddDiffOptions(f, &diff.Options)