diff --git a/cmd/helm/dependency_update.go b/cmd/helm/dependency_update.go index ad0188f17..3d7c816fd 100644 --- a/cmd/helm/dependency_update.go +++ b/cmd/helm/dependency_update.go @@ -17,12 +17,14 @@ package main import ( "io" + "os" "path/filepath" "github.com/spf13/cobra" "helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/getter" ) @@ -71,13 +73,31 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com if client.Verify { man.Verify = downloader.VerifyAlways } - return man.Update() + + err := man.Update() + if err != nil { + return err + } + + if client.Untar { + match := chartpath + "/charts/*.tgz" + files, err := filepath.Glob(match) + if err != nil { + return err + } + for _, f := range files { + chartutil.ExpandFile(chartpath+"/charts/", f) + os.Remove(f) + } + } + return nil }, } f := cmd.Flags() f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures") f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys") + f.BoolVar(&client.Untar, "untar", false, "if set to true, will untar the chart after downloading it") f.BoolVar(&client.SkipRefresh, "skip-refresh", false, "do not refresh the local repository cache") return cmd diff --git a/cmd/helm/dependency_update_test.go b/cmd/helm/dependency_update_test.go index 896018735..30aad9ef8 100644 --- a/cmd/helm/dependency_update_test.go +++ b/cmd/helm/dependency_update_test.go @@ -148,6 +148,18 @@ func TestDependencyUpdateCmd(t *testing.T) { if _, err := os.Stat(expect); err != nil { t.Fatal(err) } + // when use `--untar` flag, ./charts/*.tgz should not existed. + _, _, 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 got downloaded,and untar it. + expect = dir(chartname, "charts/reqtest") + if _, err := os.Stat(expect); err != nil { + t.Fatal(err) + } } func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) { diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go index 4c80d0159..317445ea7 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 }