Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --set-json #498

Merged
merged 1 commit into from Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/helm3.go
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
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