Skip to content

Commit

Permalink
fix: HELM_DIFF_IGNORE_UNKNOWN_FLAGS ignored issue (#538)
Browse files Browse the repository at this point in the history
* fix: HELM_DIFF_IGNORE_UNKNOWN_FLAGS ignored issue

Signed-off-by: yxxhero <[email protected]>

* remove unused file

Signed-off-by: yxxhero <[email protected]>

---------

Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero authored Jan 27, 2024
1 parent fd1038a commit 02be0bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ release/
.envrc
.idea
docker-run-release-cache/
.vscode/
14 changes: 10 additions & 4 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func newChartCommand() *cobra.Command {
diff := diffCmd{
namespace: os.Getenv("HELM_NAMESPACE"),
}
unknownFlags := os.Getenv("HELM_DIFF_IGNORE_UNKNOWN_FLAGS") == "true"

cmd := &cobra.Command{
Use: "upgrade [flags] [RELEASE] [CHART]",
Expand Down Expand Up @@ -165,13 +166,18 @@ func newChartCommand() *cobra.Command {
" --dry-run=server enables the cluster access with helm-get and the lookup template function."
)

cmdFlags := cmd.Flags()

// see: https://github.com/databus23/helm-diff/issues/537
cmdFlags.ParseErrorsWhitelist.UnknownFlags = unknownFlags

legacyDryRunFlagSet := pflag.NewFlagSet("upgrade", pflag.ContinueOnError)
legacyDryRun := legacyDryRunFlagSet.Bool("dry-run", false, dryRunUsage)
if err := legacyDryRunFlagSet.Parse(args); err == nil && *legacyDryRun {
diff.dryRunModeSpecified = true
args = legacyDryRunFlagSet.Args()
} else {
cmd.Flags().StringVar(&diff.dryRunMode, "dry-run", "", dryRunUsage)
cmdFlags.StringVar(&diff.dryRunMode, "dry-run", "", dryRunUsage)
}

// Here we parse the flags ourselves so that we can support
Expand All @@ -182,11 +188,11 @@ func newChartCommand() *cobra.Command {
//
// This works becase we have `DisableFlagParsing: true`` above.
// Never turn that off, or you'll get the error again.
if err := cmd.Flags().Parse(args); err != nil {
if err := cmdFlags.Parse(args); err != nil {
return err
}

args = cmd.Flags().Args()
args = cmdFlags.Args()

if !diff.dryRunModeSpecified {
dryRunModeSpecified := cmd.Flags().Changed("dry-run")
Expand Down Expand Up @@ -255,7 +261,7 @@ func newChartCommand() *cobra.Command {
return diff.runHelm3()
},
FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: os.Getenv("HELM_DIFF_IGNORE_UNKNOWN_FLAGS") == "true",
UnknownFlags: unknownFlags,
},
}

Expand Down

0 comments on commit 02be0bd

Please sign in to comment.