diff --git a/pkg/cmd/dependency.go b/pkg/cmd/dependency.go index bb7dfe707..b3fc00552 100644 --- a/pkg/cmd/dependency.go +++ b/pkg/cmd/dependency.go @@ -133,5 +133,5 @@ func addDependencySubcommandFlags(f *pflag.FlagSet, client *action.Dependency) { f.BoolVar(&client.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download") f.BoolVar(&client.PlainHTTP, "plain-http", false, "use insecure HTTP connections for the chart download") f.StringVar(&client.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") - f.BoolVar(&client.BuildOrUpdateRecursive, "recursive", false, "build dependencies recursively") + f.BoolVar(&client.BuildOrUpdateRecursive, "recursive", false, "build or update dependencies recursively") } diff --git a/pkg/cmd/dependency_build_test.go b/pkg/cmd/dependency_build_test.go index a3473301d..9d031457a 100644 --- a/pkg/cmd/dependency_build_test.go +++ b/pkg/cmd/dependency_build_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + chart "helm.sh/helm/v4/pkg/chart/v2" chartutil "helm.sh/helm/v4/pkg/chart/v2/util" "helm.sh/helm/v4/pkg/provenance" "helm.sh/helm/v4/pkg/repo/v1" @@ -162,3 +163,64 @@ func TestDependencyBuildCmdWithHelmV2Hash(t *testing.T) { t.Fatal(err) } } + +// createTestingChart creates a basic chart that depends on reqtest-0.1.0 +// +// The baseURL can be used to point to a particular repository server. +func createTestingChartWithRecursion(t *testing.T, dest, name, baseURL string) { + t.Helper() + cfile := &chart.Chart{ + Metadata: &chart.Metadata{ + APIVersion: chart.APIVersionV2, + Name: name, + Version: "1.2.3", + Dependencies: []*chart.Dependency{ + {Name: "reqtest", Version: "0.1.0", Repository: baseURL}, + {Name: "compressedchart", Version: "0.1.0", Repository: baseURL}, + {Name: "root", Version: "0.1.0", Repository: baseURL}, + }, + }, + } + if err := chartutil.SaveDir(cfile, dest); err != nil { + t.Fatal(err) + } +} + +func TestDependencyBuildCmdRecursive(t *testing.T) { + srv := repotest.NewTempServer( + t, + repotest.WithChartSourceGlob("testdata/testcharts/*.tgz"), + ) + defer srv.Stop() + rootDir := srv.Root() + + srv.LinkIndices() + ociSrv, err := repotest.NewOCIServer(t, rootDir) + if err != nil { + t.Fatal(err) + } + + dir := func(p ...string) string { + return filepath.Join(append([]string{rootDir}, p...)...) + } + + ociChartName := "oci-depending-chart" + c := createTestingMetadataForOCI(ociChartName, ociSrv.RegistryURL) + if _, err := chartutil.Save(c, ociSrv.Dir); err != nil { + t.Fatal(err) + } + ociSrv.Run(t, repotest.WithDependingChart(c)) + + chartname := "chart-with-multi-level-deps" + createTestingChartWithRecursion(t, dir(), chartname, srv.URL()) + repoFile := filepath.Join(dir(), "repositories.yaml") + + cmd := fmt.Sprintf("dependency build '%s' --repository-config %s --repository-cache %s --plain-http --recursive", filepath.Join(rootDir, chartname), repoFile, rootDir) + _, out, err := executeActionCommand(cmd) + + // In the first pass, we basically want the same results as an update. + if err != nil { + t.Logf("Output: %s", out) + t.Fatal(err) + } +} diff --git a/pkg/cmd/helpers_test.go b/pkg/cmd/helpers_test.go index 3f04a6a9b..5432ff2de 100644 --- a/pkg/cmd/helpers_test.go +++ b/pkg/cmd/helpers_test.go @@ -31,8 +31,8 @@ import ( "helm.sh/helm/v4/internal/test" "helm.sh/helm/v4/pkg/action" + "helm.sh/helm/v4/pkg/chart/common" "helm.sh/helm/v4/pkg/chart/v2/loader" - chartutil "helm.sh/helm/v4/pkg/chart/v2/util" "helm.sh/helm/v4/pkg/cli" kubefake "helm.sh/helm/v4/pkg/kube/fake" release "helm.sh/helm/v4/pkg/release/v1" diff --git a/pkg/cmd/testdata/output/install-dependency-update-recursive.txt b/pkg/cmd/testdata/output/install-dependency-update-recursive.txt index 9b25fbe36..16ece824e 100644 --- a/pkg/cmd/testdata/output/install-dependency-update-recursive.txt +++ b/pkg/cmd/testdata/output/install-dependency-update-recursive.txt @@ -3,4 +3,5 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +DESCRIPTION: Install complete TEST SUITE: None diff --git a/pkg/cmd/testdata/output/template-dependency-update-recursive.txt b/pkg/cmd/testdata/output/template-dependency-update-recursive.txt index 46a53092f..5c451ad75 100644 --- a/pkg/cmd/testdata/output/template-dependency-update-recursive.txt +++ b/pkg/cmd/testdata/output/template-dependency-update-recursive.txt @@ -1,11 +1,5 @@ -Hang tight while we grab the latest from your chart repositories... -...Successfully got an update from the "kube-sigs-external-dns" chart repository -Update Complete. ⎈Happy Helming!⎈ Saving 1 charts Deleting outdated charts -Hang tight while we grab the latest from your chart repositories... -...Successfully got an update from the "kube-sigs-external-dns" chart repository -Update Complete. ⎈Happy Helming!⎈ Saving 1 charts Deleting outdated charts --- diff --git a/pkg/cmd/testdata/testcharts/root-0.1.0.tgz b/pkg/cmd/testdata/testcharts/root-0.1.0.tgz new file mode 100644 index 000000000..265ce8d89 Binary files /dev/null and b/pkg/cmd/testdata/testcharts/root-0.1.0.tgz differ diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 0ce0928ab..7c4edb823 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -833,19 +833,19 @@ func (m *Manager) locateLocalDependencies(baseChartPath string, resursive bool) []string{fullDepChartPath}, reversedDeps..., ) - } - if resursive { - subDeps, err := m.locateLocalDependencies(fullDepChartPath, resursive) + if resursive { + subDeps, err := m.locateLocalDependencies(fullDepChartPath, resursive) - if err != nil { - return nil, err - } + if err != nil { + return nil, err + } - reversedDeps = append( - subDeps, - reversedDeps..., - ) + reversedDeps = append( + subDeps, + reversedDeps..., + ) + } } }