From b29b73f8d823601024d8e70dd5b274474fd9d20d Mon Sep 17 00:00:00 2001 From: Andrea Tartaglia Date: Mon, 3 Mar 2025 12:25:03 +0100 Subject: [PATCH] add untar option to dependency update Signed-off-by: Andrea Tartaglia --- pkg/action/dependency.go | 1 + pkg/cmd/dependency.go | 1 + pkg/cmd/dependency_update.go | 1 + pkg/cmd/dependency_update_test.go | 14 +++++++++++++- pkg/downloader/manager.go | 6 ++++-- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go index 03c370c8e..9e932b50c 100644 --- a/pkg/action/dependency.go +++ b/pkg/action/dependency.go @@ -35,6 +35,7 @@ import ( // It provides the implementation of 'helm dependency' and its respective subcommands. type Dependency struct { Verify bool + Untar bool Keyring string SkipRefresh bool ColumnWidth uint diff --git a/pkg/cmd/dependency.go b/pkg/cmd/dependency.go index 34bbff6be..b1f4b2273 100644 --- a/pkg/cmd/dependency.go +++ b/pkg/cmd/dependency.go @@ -133,4 +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.Untar, "untar", false, "if set to true, will untar the chart after downloading it") } diff --git a/pkg/cmd/dependency_update.go b/pkg/cmd/dependency_update.go index b534fb48a..5a898fdeb 100644 --- a/pkg/cmd/dependency_update.go +++ b/pkg/cmd/dependency_update.go @@ -69,6 +69,7 @@ func newDependencyUpdateCmd(_ *action.Configuration, out io.Writer) *cobra.Comma ChartPath: chartpath, Keyring: client.Keyring, SkipUpdate: client.SkipRefresh, + Untar: client.Untar, Getters: getter.All(settings), RegistryClient: registryClient, RepositoryConfig: settings.RepositoryConfig, diff --git a/pkg/cmd/dependency_update_test.go b/pkg/cmd/dependency_update_test.go index 3eaa51df1..b9d3943a8 100644 --- a/pkg/cmd/dependency_update_test.go +++ b/pkg/cmd/dependency_update_test.go @@ -149,6 +149,19 @@ func TestDependencyUpdateCmd(t *testing.T) { if _, err := os.Stat(expect); err != nil { t.Fatal(err) } + + // When using `--untar`, ./charts/*.tgz should not exist + _, _, err = executeActionCommand( + fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s --untar", dir(chartname), dir("repositories.yaml"), dir()), + ) + if err != nil { + t.Fatal(err) + } + // Make sure the actual file is downloaded and untar + expect = dir(chartname, "charts/reqtest") + if _, err := os.Stat(expect); err != nil { + t.Fatal(err) + } } func TestDependencyUpdateCmd_DoNotDeleteOldChartsOnError(t *testing.T) { @@ -241,7 +254,6 @@ func TestDependencyUpdateCmd_WithRepoThatWasNotAdded(t *testing.T) { fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s --content-cache %s", dir(chartname), dir("repositories.yaml"), dir(), contentCache), ) - if err != nil { t.Logf("Output: %s", out) t.Fatal(err) diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index d41b8fdb4..710fb7a9c 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -361,6 +361,10 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { break } + if m.Untar { + chartutil.ExpandFile(m.ChartPath+"/charts/", tmpPath) + } + churls[churl] = struct{}{} } @@ -502,7 +506,6 @@ Loop: // in a known repo and attempt to ensure the data is present for steps like // version resolution. func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.Dependency) (map[string]string, error) { - var ru []*repo.Entry for _, dd := range deps { @@ -679,7 +682,6 @@ func dedupeRepos(repos []*repo.Entry) []*repo.Entry { } func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error { - var wg sync.WaitGroup localRepos := dedupeRepos(repos)