Skip to content

Commit

Permalink
allow reuse-values on upgrade to be configurable
Browse files Browse the repository at this point in the history
many charts add new values between chart versions. When using the
reuse-values flag, those charts fail because reuse-values ignores the
default values file.

By making this configurable, it allows the chart maintainer to determine
whether it's appropriate for their chart to add new values when
upgrading.

Signed-off-by: Joe Julian <[email protected]>
  • Loading branch information
joejulian committed Mar 11, 2023
1 parent b8ad35c commit aa94b9a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ct/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func addInstallFlags(flags *flag.FlagSet) {
(e.g. "--set=name=value"`))
flags.Bool("skip-clean-up", false, heredoc.Doc(`
Skip resources clean-up. Used if need to continue other flows or keep it around.`))
flags.Bool("reuse-values", true, heredoc.Doc(`
Can be reset to disable adding the reuse-values flag for upgrades when
using the --upgrade flag.`))
}

func install(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func NewTesting(config config.Configuration, extraSetArgs string) (Testing, erro

testing := Testing{
config: config,
helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs)),
helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs), config.ReuseValues),
git: tool.NewGit(procExec),
kubectl: tool.NewKubectl(procExec, config.KubectlTimeout),
linter: tool.NewLinter(procExec),
Expand Down
2 changes: 1 addition & 1 deletion pkg/chart/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Te
utils: util.Utils{},
accountValidator: fakeAccountValidator{},
linter: fakeMockLinter,
helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs)),
helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs), cfg.ReuseValues),
kubectl: tool.NewKubectl(procExec, 30*time.Second),
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Configuration struct {
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"`
PrintLogs bool `mapstructure:"print-logs"`
ReuseValues bool `mapstructure:"reuse-values"`
}

func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*Configuration, error) {
Expand Down
10 changes: 8 additions & 2 deletions pkg/tool/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ type Helm struct {
exec exec.ProcessExecutor
extraArgs []string
extraSetArgs []string
reuseValues bool
}

func NewHelm(exec exec.ProcessExecutor, extraArgs []string, extraSetArgs []string) Helm {
func NewHelm(exec exec.ProcessExecutor, extraArgs []string, extraSetArgs []string, reuseValues bool) Helm {
return Helm{
exec: exec,
extraArgs: extraArgs,
extraSetArgs: extraSetArgs,
reuseValues: reuseValues,
}
}

Expand Down Expand Up @@ -70,8 +72,12 @@ func (h Helm) InstallWithValues(chart string, valuesFile string, namespace strin
}

func (h Helm) Upgrade(chart string, namespace string, release string) error {
var reuseValuesFlag string
if h.reuseValues {
reuseValuesFlag = "--reuse-values"
}
if err := h.exec.RunProcess("helm", "upgrade", release, chart, "--namespace", namespace,
"--reuse-values", "--wait", h.extraArgs, h.extraSetArgs); err != nil {
reuseValuesFlag, "--wait", h.extraArgs, h.extraSetArgs); err != nil {
return err
}

Expand Down

0 comments on commit aa94b9a

Please sign in to comment.