Skip to content

Commit 02be0bd

Browse files
authored
fix: HELM_DIFF_IGNORE_UNKNOWN_FLAGS ignored issue (#538)
* 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]>
1 parent fd1038a commit 02be0bd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ release/
55
.envrc
66
.idea
77
docker-run-release-cache/
8+
.vscode/

cmd/upgrade.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func newChartCommand() *cobra.Command {
108108
diff := diffCmd{
109109
namespace: os.Getenv("HELM_NAMESPACE"),
110110
}
111+
unknownFlags := os.Getenv("HELM_DIFF_IGNORE_UNKNOWN_FLAGS") == "true"
111112

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

169+
cmdFlags := cmd.Flags()
170+
171+
// see: https://github.com/databus23/helm-diff/issues/537
172+
cmdFlags.ParseErrorsWhitelist.UnknownFlags = unknownFlags
173+
168174
legacyDryRunFlagSet := pflag.NewFlagSet("upgrade", pflag.ContinueOnError)
169175
legacyDryRun := legacyDryRunFlagSet.Bool("dry-run", false, dryRunUsage)
170176
if err := legacyDryRunFlagSet.Parse(args); err == nil && *legacyDryRun {
171177
diff.dryRunModeSpecified = true
172178
args = legacyDryRunFlagSet.Args()
173179
} else {
174-
cmd.Flags().StringVar(&diff.dryRunMode, "dry-run", "", dryRunUsage)
180+
cmdFlags.StringVar(&diff.dryRunMode, "dry-run", "", dryRunUsage)
175181
}
176182

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

189-
args = cmd.Flags().Args()
195+
args = cmdFlags.Args()
190196

191197
if !diff.dryRunModeSpecified {
192198
dryRunModeSpecified := cmd.Flags().Changed("dry-run")
@@ -255,7 +261,7 @@ func newChartCommand() *cobra.Command {
255261
return diff.runHelm3()
256262
},
257263
FParseErrWhitelist: cobra.FParseErrWhitelist{
258-
UnknownFlags: os.Getenv("HELM_DIFF_IGNORE_UNKNOWN_FLAGS") == "true",
264+
UnknownFlags: unknownFlags,
259265
},
260266
}
261267

0 commit comments

Comments
 (0)