Fix repo cache setting

Fix `repo add` and `repo update` to use a repository cache set
using `--repository-cache` flag

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Signed-off-by: Trond Hindenes <trond@hindenes.com>
pull/8158/head
Martin Hickey 5 years ago
parent 372b09134c
commit 2ae83f276b

@ -130,6 +130,9 @@ func (o *repoAddOptions) run(out io.Writer) error {
return err return err
} }
if o.repoCache != "" {
r.CachePath = o.repoCache
}
if _, err := r.DownloadIndexFile(); err != nil { if _, err := r.DownloadIndexFile(); err != nil {
return errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", o.url) return errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", o.url)
} }

@ -37,8 +37,9 @@ Information is cached locally, where it is used by commands like 'helm search'.
var errNoRepositories = errors.New("no repositories found. You must add one before updating") var errNoRepositories = errors.New("no repositories found. You must add one before updating")
type repoUpdateOptions struct { type repoUpdateOptions struct {
update func([]*repo.ChartRepository, io.Writer) update func([]*repo.ChartRepository, io.Writer)
repoFile string repoFile string
repoCache string
} }
func newRepoUpdateCmd(out io.Writer) *cobra.Command { func newRepoUpdateCmd(out io.Writer) *cobra.Command {
@ -52,6 +53,7 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
Args: require.NoArgs, Args: require.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
o.repoFile = settings.RepositoryConfig o.repoFile = settings.RepositoryConfig
o.repoCache = settings.RepositoryCache
return o.run(out) return o.run(out)
}, },
} }
@ -69,6 +71,9 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
if err != nil { if err != nil {
return err return err
} }
if o.repoCache != "" {
r.CachePath = o.repoCache
}
repos = append(repos, r) repos = append(repos, r)
} }

@ -19,6 +19,8 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -79,3 +81,34 @@ func TestUpdateCharts(t *testing.T) {
t.Error("Update was not successful") t.Error("Update was not successful")
} }
} }
func TestUpdateChartsCustomCache(t *testing.T) {
defer resetEnv()()
defer ensure.HelmHome(t)()
ts, err := repotest.NewTempServer("testdata/testserver/*.*")
if err != nil {
t.Fatal(err)
}
defer ts.Stop()
r, err := repo.NewChartRepository(&repo.Entry{
Name: "charts",
URL: ts.URL(),
}, getter.All(settings))
if err != nil {
t.Error(err)
}
cachePath := ensure.TempDir(t)
cacheFile := filepath.Join(cachePath, "charts-index.yaml")
r.CachePath = cachePath
b := bytes.NewBuffer(nil)
updateCharts([]*repo.ChartRepository{r}, b)
_, err = ioutil.ReadFile(cacheFile)
if err != nil {
t.Error(err)
}
}

Loading…
Cancel
Save