From 15582ec4dcf8e406e62a0eaf97cab7069955cd30 Mon Sep 17 00:00:00 2001 From: kamilswiec <31224592+kamilswiec@users.noreply.github.com> Date: Mon, 28 Apr 2025 21:40:40 +0200 Subject: [PATCH] feat:support --dependency-update before upgrade Signed-off-by: kamilswiec <31224592+kamilswiec@users.noreply.github.com> --- cmd/helm3.go | 6 ++++++ cmd/upgrade.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/helm3.go b/cmd/helm3.go index 1e9df931..03a7f365 100644 --- a/cmd/helm3.go +++ b/cmd/helm3.go @@ -74,6 +74,12 @@ func getRelease(release, namespace string) ([]byte, error) { return outputWithRichError(cmd) } +func updateDependencies(chart string) ([]byte, error) { + args := []string{"dependency", "update", chart} + cmd := exec.Command(os.Getenv("HELM_BIN"), args...) + return outputWithRichError(cmd) +} + func getHooks(release, namespace string) ([]byte, error) { args := []string{"get", "hooks", release} if namespace != "" { diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 75281af4..7c20fda3 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -51,6 +51,7 @@ type diffCmd struct { resetValues bool resetThenReuseValues bool allowUnreleased bool + dependencyUpdate bool noHooks bool includeTests bool includeCRDs bool @@ -240,6 +241,7 @@ func newChartCommand() *cobra.Command { f.BoolVar(&diff.resetThenReuseValues, "reset-then-reuse-values", false, "reset the values to the ones built into the chart, apply the last release's values and merge in any new values. If '--reset-values' or '--reuse-values' is specified, this is ignored") f.BoolVar(&diff.allowUnreleased, "allow-unreleased", false, "enables diffing of releases that are not yet deployed via Helm") f.BoolVar(&diff.install, "install", false, "enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match \"helm upgrade --install\" command") + f.BoolVar(&diff.dependencyUpdate, "dependency-update", false, "update dependencies if they are missing before diffing") f.BoolVar(&diff.noHooks, "no-hooks", false, "disable diffing of hooks") f.BoolVar(&diff.includeTests, "include-tests", false, "enable the diffing of the helm test hooks") f.BoolVar(&diff.includeCRDs, "include-crds", false, "include CRDs in the diffing") @@ -271,6 +273,16 @@ func (d *diffCmd) runHelm3() error { var err error + if d.dependencyUpdate { + var output []byte + output, err = updateDependencies(d.chart) + if err != nil { + return err + } else { + fmt.Println(string(output)) + } + } + if d.takeOwnership { // We need to do a three way merge between the manifests of the new // release, the manifests of the old release and what is currently deployed