Skip to content

Commit

Permalink
avoid adding new public function
Browse files Browse the repository at this point in the history
Signed-off-by: CI <ci@argoproj.com>
(cherry picked from commit cd76fcd)
  • Loading branch information
CI authored and mattfarina committed Oct 12, 2022
1 parent 959acd8 commit 75a1369
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/helm/repo_add.go
Expand Up @@ -207,7 +207,7 @@ func (o *repoAddOptions) run(out io.Writer) error {
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)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/repo_update.go
Expand Up @@ -122,7 +122,7 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdate
wg.Add(1)
go func(re *repo.ChartRepository) {
defer wg.Done()
if _, _, err := re.DownloadIndexFile(); err != nil {
if _, err := re.DownloadIndexFile(); 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)
repoFailList = append(repoFailList, re.Config.URL)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/manager.go
Expand Up @@ -670,7 +670,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(); err != nil {
// For those dependencies that are not known to helm and using a
// generated key name we display the repo url.
if strings.HasPrefix(r.Config.Name, managerKeyPrefix) {
Expand Down
19 changes: 10 additions & 9 deletions pkg/repo/chartrepo.go
Expand Up @@ -115,10 +115,10 @@ func (r *ChartRepository) Load() error {
}

// DownloadIndexFile fetches the index from a repository.
func (r *ChartRepository) DownloadIndexFile() (string, string, error) {
func (r *ChartRepository) DownloadIndexFile() (string, error) {
parsedURL, err := url.Parse(r.Config.URL)
if err != nil {
return "", "", err
return "", err
}
parsedURL.RawPath = path.Join(parsedURL.RawPath, "index.yaml")
parsedURL.Path = path.Join(parsedURL.Path, "index.yaml")
Expand All @@ -133,17 +133,17 @@ func (r *ChartRepository) DownloadIndexFile() (string, string, error) {
getter.WithPassCredentialsAll(r.Config.PassCredentialsAll),
)
if err != nil {
return "", "", err
return "", err
}

index, err := ioutil.ReadAll(resp)
if err != nil {
return "", "", err
return "", err
}

indexFile, err := loadIndex(index, r.Config.URL)
if err != nil {
return "", "", err
return "", err
}

// Create the chart list file in the cache directory
Expand All @@ -158,7 +158,7 @@ func (r *ChartRepository) DownloadIndexFile() (string, string, error) {
// Create the index file in the cache directory
fname := filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name))
os.MkdirAll(filepath.Dir(fname), 0755)
return fname, chartsFile, ioutil.WriteFile(fname, index, 0644)
return fname, ioutil.WriteFile(fname, index, 0644)
}

// Index generates an index for the chart repository and writes an index.yaml file.
Expand Down Expand Up @@ -249,13 +249,14 @@ func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName,
if err != nil {
return "", err
}
idx, chart, err := r.DownloadIndexFile()
// Use a random path name so it can be deleted for cleanup.
r.CachePath = helmpath.CachePath(name)
idx, err := r.DownloadIndexFile()
if err != nil {
return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL)
}
// Clean up temp files.
defer os.RemoveAll(idx)
defer os.RemoveAll(chart)
defer os.RemoveAll(r.CachePath)

// Read the index file for the repository to get chart information and return chart URL
repoIndex, err := LoadIndexFile(idx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/chartrepo_test.go
Expand Up @@ -157,7 +157,7 @@ func TestIndexCustomSchemeDownload(t *testing.T) {
}
defer os.Remove(tempIndexFile.Name())

idx, _, err := repo.DownloadIndexFile()
idx, err := repo.DownloadIndexFile()
if err != nil {
t.Fatalf("Failed to download index file to %s: %v", idx, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/repo/index_test.go
Expand Up @@ -237,7 +237,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepo, err)
}

idx, _, err := r.DownloadIndexFile()
idx, err := r.DownloadIndexFile()
if err != nil {
t.Fatalf("Failed to download index file to %s: %#v", idx, err)
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepo, err)
}

idx, _, err := r.DownloadIndexFile()
idx, err := r.DownloadIndexFile()
if err != nil {
t.Fatalf("Failed to download index file to %s: %#v", idx, err)
}
Expand Down

0 comments on commit 75a1369

Please sign in to comment.