Skip to content

Commit

Permalink
Support --set-json (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
euroelessar authored Jan 3, 2024
1 parent a270663 commit 857da53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
if d.insecureSkipTLSVerify {
flags = append(flags, "--insecure-skip-tls-verify")
}
// Helm automatically enable --reuse-values when there's no --set, --set-string, --set-values, --set-file present.
// Helm automatically enable --reuse-values when there's no --set, --set-string, --set-json, --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
shouldDefaultReusingValues := isUpgrade && len(d.values) == 0 && len(d.stringValues) == 0 && len(d.valueFiles) == 0 && len(d.fileValues) == 0
shouldDefaultReusingValues := isUpgrade && len(d.values) == 0 && len(d.stringValues) == 0 && len(d.jsonValues) == 0 && len(d.valueFiles) == 0 && len(d.fileValues) == 0
if (d.reuseValues || shouldDefaultReusingValues) && !d.resetValues && !d.dryRun {
tmpfile, err := os.CreateTemp("", "existing-values")
if err != nil {
Expand All @@ -150,6 +150,9 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) {
for _, stringValue := range d.stringValues {
flags = append(flags, "--set-string", stringValue)
}
for _, jsonValue := range d.jsonValues {
flags = append(flags, "--set-json", jsonValue)
}
for _, valueFile := range d.valueFiles {
if strings.TrimSpace(valueFile) == "-" {
bytes, err := io.ReadAll(os.Stdin)
Expand Down
2 changes: 2 additions & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type diffCmd struct {
valueFiles valueFiles
values []string
stringValues []string
jsonValues []string
fileValues []string
reuseValues bool
resetValues bool
Expand Down Expand Up @@ -183,6 +184,7 @@ func newChartCommand() *cobra.Command {
f.VarP(&diff.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)")
f.StringArrayVar(&diff.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&diff.stringValues, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&diff.jsonValues, "set-json", []string{}, "set JSON values on the command line (can specify multiple or separate values with commas: key1=jsonval1,key2=jsonval2)")
f.StringArrayVar(&diff.fileValues, "set-file", []string{}, "set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)")
f.BoolVar(&diff.reuseValues, "reuse-values", false, "reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored")
f.BoolVar(&diff.resetValues, "reset-values", false, "reset the values to the ones built into the chart and merge in any new values")
Expand Down

0 comments on commit 857da53

Please sign in to comment.