Merge pull request #1975 from technosophos/fix/1974-fix-broken-cache-files

fix(helm): fix broken cache paths in repositories
pull/1989/head
Matt Butcher 8 years ago committed by GitHub
commit 41f9d4059a

@ -21,6 +21,7 @@ import (
"io"
"github.com/spf13/cobra"
"k8s.io/helm/cmd/helm/helmpath"
)
var longHomeHelp = `
@ -34,7 +35,17 @@ func newHomeCmd(out io.Writer) *cobra.Command {
Short: "displays the location of HELM_HOME",
Long: longHomeHelp,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(out, homePath()+"\n")
h := helmpath.Home(homePath())
fmt.Fprintf(out, "%s\n", h)
if flagDebug {
fmt.Fprintf(out, "Repository: %s\n", h.Repository())
fmt.Fprintf(out, "RepositoryFile: %s\n", h.RepositoryFile())
fmt.Fprintf(out, "Cache: %s\n", h.Cache())
fmt.Fprintf(out, "Stable CacheIndex: %s\n", h.CacheIndex("stable"))
fmt.Fprintf(out, "Starters: %s\n", h.Starters())
fmt.Fprintf(out, "LocalRepository: %s\n", h.LocalRepository())
fmt.Fprintf(out, "Plugins: %s\n", h.Plugins())
}
},
}

@ -228,7 +228,9 @@ func initStableRepo(cacheFile string) (*repo.Entry, error) {
return nil, err
}
if err := r.DownloadIndexFile(); err != nil {
// In this case, the cacheFile is always absolute. So passing empty string
// is safe.
if err := r.DownloadIndexFile(""); err != nil {
return nil, fmt.Errorf("Looks like %q is not a valid chart repository or cannot be reached: %s", stableRepositoryURL, err.Error())
}

@ -102,7 +102,7 @@ func addRepository(name, url string, home helmpath.Home, certFile, keyFile, caFi
return err
}
if err := r.DownloadIndexFile(); err != nil {
if err := r.DownloadIndexFile(home.Cache()); err != nil {
return fmt.Errorf("Looks like %q is not a valid chart repository or cannot be reached: %s", url, err.Error())
}

@ -41,7 +41,7 @@ var (
)
type repoUpdateCmd struct {
update func([]*repo.ChartRepository, io.Writer)
update func([]*repo.ChartRepository, io.Writer, helmpath.Home)
home helmpath.Home
out io.Writer
}
@ -82,11 +82,11 @@ func (u *repoUpdateCmd) run() error {
repos = append(repos, r)
}
u.update(repos, u.out)
u.update(repos, u.out, u.home)
return nil
}
func updateCharts(repos []*repo.ChartRepository, out io.Writer) {
func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Home) {
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var wg sync.WaitGroup
for _, re := range repos {
@ -94,10 +94,10 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer) {
go func(re *repo.ChartRepository) {
defer wg.Done()
if re.Config.Name == localRepository {
fmt.Fprintf(out, "...Skip %s chart repository", re.Config.Name)
fmt.Fprintf(out, "...Skip %s chart repository\n", re.Config.Name)
return
}
err := re.DownloadIndexFile()
err := re.DownloadIndexFile(home.Cache())
if err != nil {
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err)
} else {

@ -43,7 +43,7 @@ func TestUpdateCmd(t *testing.T) {
out := bytes.NewBuffer(nil)
// Instead of using the HTTP updater, we provide our own for this test.
// The TestUpdateCharts test verifies the HTTP behavior independently.
updater := func(repos []*repo.ChartRepository, out io.Writer) {
updater := func(repos []*repo.ChartRepository, out io.Writer, hh helmpath.Home) {
for _, re := range repos {
fmt.Fprintln(out, re.Config.Name)
}
@ -90,7 +90,7 @@ func TestUpdateCharts(t *testing.T) {
}
b := bytes.NewBuffer(nil)
updateCharts([]*repo.ChartRepository{r}, b)
updateCharts([]*repo.ChartRepository{r}, b, hh)
got := b.String()
if strings.Contains(got, "Unable to get an update") {

@ -30,7 +30,10 @@ import (
"github.com/Masterminds/semver"
"github.com/ghodss/yaml"
// FIXME: This violates the package rules. A `cmd` should not be imported by
// something in 'pkg'
"k8s.io/helm/cmd/helm/helmpath"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/repo"
@ -375,7 +378,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
}
wg.Add(1)
go func(r *repo.ChartRepository) {
if err := r.DownloadIndexFile(); err != nil {
if err := r.DownloadIndexFile(m.HelmHome.Cache()); err != nil {
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err)
} else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", r.Config.Name)

@ -129,7 +129,10 @@ func (r *ChartRepository) Load() error {
}
// DownloadIndexFile fetches the index from a repository.
func (r *ChartRepository) DownloadIndexFile() error {
//
// cachePath is prepended to any index that does not have an absolute path. This
// is for pre-2.2.0 repo files.
func (r *ChartRepository) DownloadIndexFile(cachePath string) error {
var indexURL string
indexURL = strings.TrimSuffix(r.Config.URL, "/") + "/index.yaml"
@ -148,7 +151,19 @@ func (r *ChartRepository) DownloadIndexFile() error {
return err
}
return ioutil.WriteFile(r.Config.Cache, index, 0644)
// In Helm 2.2.0 the config.cache was accidentally switched to an absolute
// path, which broke backward compatibility. This fixes it by prepending a
// global cache path to relative paths.
//
// It is changed on DownloadIndexFile because that was the method that
// originally carried the cache path.
cp := r.Config.Cache
if !filepath.IsAbs(cp) {
cp = filepath.Join(cachePath, cp)
}
println("Writing to", cp)
return ioutil.WriteFile(cp, index, 0644)
}
// Index generates an index for the chart repository and writes an index.yaml file.

@ -142,7 +142,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepo, err)
}
if err := r.DownloadIndexFile(); err != nil {
if err := r.DownloadIndexFile(""); err != nil {
t.Errorf("%#v", err)
}

Loading…
Cancel
Save