Skip to content

Commit 86aa528

Browse files
committed
fix: use 'helm dependency update' command because --dependency-update flag will not update on chart changes
Signed-off-by: Russell Centanni <[email protected]>
1 parent aa3e1d2 commit 86aa528

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

e2e/tests/deploy/deploy.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package deploy
22

33
import (
4+
"bytes"
45
"context"
56
"os"
67
"path/filepath"
78
"strings"
89

10+
"github.com/loft-sh/devspace/pkg/util/log"
11+
"github.com/onsi/gomega"
12+
"github.com/sirupsen/logrus"
13+
914
"github.com/onsi/ginkgo/v2"
1015

1116
"github.com/loft-sh/devspace/cmd"
@@ -679,4 +684,72 @@ var _ = DevSpaceDescribe("deploy", func() {
679684
framework.ExpectEqual(out2, "test")
680685
framework.ExpectEqual(out3, "test")
681686
})
687+
688+
ginkgo.It("should run helm dependency update on dependency's local chart name", func() {
689+
tempDir, err := framework.CopyToTempDir("tests/deploy/testdata/helm_git_dependency_with_local_chart")
690+
framework.ExpectNoError(err)
691+
defer framework.CleanupTempDir(initialDir, tempDir)
692+
693+
ns, err := kubeClient.CreateNamespace("deploy")
694+
framework.ExpectNoError(err)
695+
defer func() {
696+
err := kubeClient.DeleteNamespace(ns)
697+
framework.ExpectNoError(err)
698+
}()
699+
700+
// create a new dev command
701+
output := &bytes.Buffer{}
702+
deployCmd := &cmd.RunPipelineCmd{
703+
GlobalFlags: &flags.GlobalFlags{
704+
NoWarn: true,
705+
Namespace: ns,
706+
ConfigPath: "devspace-name.yaml",
707+
},
708+
Pipeline: "deploy",
709+
Log: log.NewStreamLogger(output, output, logrus.DebugLevel),
710+
}
711+
712+
// run the command
713+
err = deployCmd.RunDefault(f)
714+
framework.ExpectNoError(err)
715+
716+
// Expect helm dependency update to be run.
717+
gomega.Expect(output.String()).To(
718+
gomega.ContainSubstring("helm dependency update"),
719+
)
720+
})
721+
722+
ginkgo.It("should run helm dependency update on dependency's local chart name and path", func() {
723+
tempDir, err := framework.CopyToTempDir("tests/deploy/testdata/helm_git_dependency_with_local_chart")
724+
framework.ExpectNoError(err)
725+
defer framework.CleanupTempDir(initialDir, tempDir)
726+
727+
ns, err := kubeClient.CreateNamespace("deploy")
728+
framework.ExpectNoError(err)
729+
defer func() {
730+
err := kubeClient.DeleteNamespace(ns)
731+
framework.ExpectNoError(err)
732+
}()
733+
734+
// create a new dev command
735+
output := &bytes.Buffer{}
736+
deployCmd := &cmd.RunPipelineCmd{
737+
GlobalFlags: &flags.GlobalFlags{
738+
NoWarn: true,
739+
Namespace: ns,
740+
ConfigPath: "devspace-path.yaml",
741+
},
742+
Pipeline: "deploy",
743+
Log: log.NewStreamLogger(output, output, logrus.DebugLevel),
744+
}
745+
746+
// run the command
747+
err = deployCmd.RunDefault(f)
748+
framework.ExpectNoError(err)
749+
750+
// Expect helm dependency update to be run.
751+
gomega.Expect(output.String()).To(
752+
gomega.ContainSubstring("helm dependency update"),
753+
)
754+
})
682755
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2beta1
2+
3+
dependencies:
4+
dependency:
5+
git: https://github.com/loft-sh/e2e-test-dependency.git
6+
branch: helm-with-local-chart
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: v2beta1
2+
3+
dependencies:
4+
dependency:
5+
git: https://github.com/loft-sh/e2e-test-dependency.git
6+
branch: helm-with-local-chart
7+
subPath: config-with-path

pkg/devspace/helm/generic/generic.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package generic
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
"strings"
8+
69
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
710
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
811
"github.com/loft-sh/utils/pkg/command"
9-
"os"
10-
"strings"
1112

1213
"gopkg.in/yaml.v3"
1314

@@ -76,7 +77,7 @@ func (c *client) Exec(ctx devspacecontext.Context, args []string) ([]byte, error
7677

7778
// disable log for list, because it prints same command multiple times if we've multiple deployments.
7879
if args[0] != "list" && args[0] != "registry" && (len(args) == 1 || args[1] != "login") {
79-
c.log.Debugf("Execute '%s %s'", c.helmPath, strings.Join(args, " "))
80+
c.log.Debugf("Execute '%s %s' in directory %s", c.helmPath, strings.Join(args, " "), ctx.WorkingDir())
8081
}
8182

8283
result, err := command.Output(ctx.Context(), ctx.WorkingDir(), ctx.Environ(), c.helmPath, args...)

pkg/devspace/helm/v3/client.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ func (c *client) InstallChart(ctx devspacecontext.Context, releaseName string, r
111111
if helmConfig.DisableDependencyUpdate == nil || (helmConfig.DisableDependencyUpdate != nil && !*helmConfig.DisableDependencyUpdate) {
112112
stat, err := os.Stat(chartPath)
113113
if err == nil && stat.IsDir() {
114-
args = append(args, "--dependency-update")
114+
// Do not use --dependency-update because it will not update dependencies when the Chart.yaml is updated:
115+
// https://github.com/helm/helm/issues/9545
116+
_, err := c.genericHelm.Exec(ctx.WithWorkingDir(chartPath), []string{"dependency", "update"})
117+
if err != nil {
118+
ctx.Log().Warnf("error running helm dependency update: %v", err)
119+
}
115120
}
116121
}
117122
// Upgrade options
@@ -194,7 +199,12 @@ func (c *client) Template(ctx devspacecontext.Context, releaseName, releaseNames
194199
if helmConfig.DisableDependencyUpdate == nil || (helmConfig.DisableDependencyUpdate != nil && !*helmConfig.DisableDependencyUpdate) {
195200
stat, err := os.Stat(chartPath)
196201
if err == nil && stat.IsDir() {
197-
args = append(args, "--dependency-update")
202+
// Do not use --dependency-update because it will not update dependencies when the Chart.yaml is updated:
203+
// https://github.com/helm/helm/issues/9545
204+
_, err := c.genericHelm.Exec(ctx.WithWorkingDir(chartPath), []string{"dependency", "update"})
205+
if err != nil {
206+
ctx.Log().Warnf("error running helm dependency update: %v", err)
207+
}
198208
}
199209
}
200210
args = append(args, helmConfig.TemplateArgs...)

0 commit comments

Comments
 (0)