Merge pull request #8158 from hickeyma/fix-repo-cache-set

fix(repo): Repo cache setting not recognized
pull/8167/head
Martin Hickey 4 years ago committed by GitHub
commit cc8f8024a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
} }

@ -39,6 +39,7 @@ var errNoRepositories = errors.New("no repositories found. You must add one befo
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"
"os"
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -50,6 +52,25 @@ func TestUpdateCmd(t *testing.T) {
} }
} }
func TestUpdateCustomCacheCmd(t *testing.T) {
var out bytes.Buffer
rootDir := ensure.TempDir(t)
cachePath := filepath.Join(rootDir, "updcustomcache")
_ = os.Mkdir(cachePath, os.ModePerm)
defer os.RemoveAll(cachePath)
o := &repoUpdateOptions{
update: updateCharts,
repoFile: "testdata/repositories.yaml",
repoCache: cachePath,
}
if err := o.run(&out); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(cachePath, "charts-index.yaml")); err != nil {
t.Fatalf("error finding created index file in custom cache: %#v", err)
}
}
func TestUpdateCharts(t *testing.T) { func TestUpdateCharts(t *testing.T) {
defer resetEnv()() defer resetEnv()()
defer ensure.HelmHome(t)() defer ensure.HelmHome(t)()

Loading…
Cancel
Save