support `--untar` flag for dep update

Signed-off-by: Weiping Cai <weiping.cai@daocloud.io>
pull/8499/head
Weiping Cai 5 years ago
parent a9c581584f
commit c7abc018c2
No known key found for this signature in database
GPG Key ID: 97CBE6D7C8EBC386

@ -17,12 +17,14 @@ package main
import ( import (
"io" "io"
"os"
"path/filepath" "path/filepath"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/cmd/helm/require"
"helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
) )
@ -71,13 +73,31 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com
if client.Verify { if client.Verify {
man.Verify = downloader.VerifyAlways 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 := cmd.Flags()
f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures") f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures")
f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys") 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") f.BoolVar(&client.SkipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
return cmd return cmd

@ -148,6 +148,18 @@ func TestDependencyUpdateCmd(t *testing.T) {
if _, err := os.Stat(expect); err != nil { if _, err := os.Stat(expect); err != nil {
t.Fatal(err) 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) { func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) {

@ -35,6 +35,7 @@ import (
// It provides the implementation of 'helm dependency' and its respective subcommands. // It provides the implementation of 'helm dependency' and its respective subcommands.
type Dependency struct { type Dependency struct {
Verify bool Verify bool
Untar bool
Keyring string Keyring string
SkipRefresh bool SkipRefresh bool
} }

Loading…
Cancel
Save