preserve backwards compatibility

create new functions instead of modifying existing ones

Signed-off-by: Russell Cousineau <russell.cousineau@xandr.com>
pull/9604/head
Russell Cousineau 5 years ago
parent a590688b15
commit 6019257a05

@ -109,7 +109,7 @@ func TestDependencyBuildCmd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
i, err := repo.LoadIndexFile(filepath.Join(rootDir, "index.yaml"), false) i, err := repo.LoadIndexFile(filepath.Join(rootDir, "index.yaml"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -96,7 +96,7 @@ func TestDependencyUpdateCmd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
i, err := repo.LoadIndexFile(dir(helmpath.CacheIndexFile("test")), false) i, err := repo.LoadIndexFile(dir(helmpath.CacheIndexFile("test")))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -150,7 +150,7 @@ func compVersionFlag(chartRef string, toComplete string) ([]string, cobra.ShellC
path := filepath.Join(settings.RepositoryCache, helmpath.CacheIndexFile(repoName)) path := filepath.Join(settings.RepositoryCache, helmpath.CacheIndexFile(repoName))
var versions []string var versions []string
if indexFile, err := repo.LoadIndexFile(path, false); err == nil { if indexFile, err := repo.LoadIndexFile(path); err == nil {
for _, details := range indexFile.Entries[chartName] { for _, details := range indexFile.Entries[chartName] {
version := details.Metadata.Version version := details.Metadata.Version
if strings.HasPrefix(version, toComplete) { if strings.HasPrefix(version, toComplete) {

@ -182,7 +182,12 @@ func (o *repoAddOptions) run(out io.Writer) error {
if o.repoCache != "" { if o.repoCache != "" {
r.CachePath = o.repoCache r.CachePath = o.repoCache
} }
if _, err := r.DownloadIndexFile(o.hideValidationWarnings); err != nil { if o.hideValidationWarnings {
_, err = r.DownloadIndexFileHideValidationWarnings()
} else {
_, err = r.DownloadIndexFile()
}
if 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)
} }

@ -97,7 +97,7 @@ func index(dir, url, mergeTo string) error {
i2 = repo.NewIndexFile() i2 = repo.NewIndexFile()
i2.WriteFile(mergeTo, 0644) i2.WriteFile(mergeTo, 0644)
} else { } else {
i2, err = repo.LoadIndexFile(mergeTo, false) i2, err = repo.LoadIndexFile(mergeTo)
if err != nil { if err != nil {
return errors.Wrap(err, "merge failed") return errors.Wrap(err, "merge failed")
} }

@ -49,7 +49,7 @@ func TestRepoIndexCmd(t *testing.T) {
destIndex := filepath.Join(dir, "index.yaml") destIndex := filepath.Join(dir, "index.yaml")
index, err := repo.LoadIndexFile(destIndex, false) index, err := repo.LoadIndexFile(destIndex)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -90,7 +90,7 @@ func TestRepoIndexCmd(t *testing.T) {
t.Error(err) t.Error(err)
} }
index, err = repo.LoadIndexFile(destIndex, false) index, err = repo.LoadIndexFile(destIndex)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -119,7 +119,7 @@ func TestRepoIndexCmd(t *testing.T) {
t.Error(err) t.Error(err)
} }
index, err = repo.LoadIndexFile(destIndex, false) index, err = repo.LoadIndexFile(destIndex)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -98,7 +98,13 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, hideValidationWa
wg.Add(1) wg.Add(1)
go func(re *repo.ChartRepository) { go func(re *repo.ChartRepository) {
defer wg.Done() defer wg.Done()
if _, err := re.DownloadIndexFile(hideValidationWarnings); err != nil { var err error
if hideValidationWarnings {
_, err = re.DownloadIndexFileHideValidationWarnings()
} else {
_, err = re.DownloadIndexFile()
}
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) 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 { } else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name) fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name)

@ -186,7 +186,12 @@ func (o *searchRepoOptions) buildIndex() (*search.Index, error) {
for _, re := range rf.Repositories { for _, re := range rf.Repositories {
n := re.Name n := re.Name
f := filepath.Join(o.repoCacheDir, helmpath.CacheIndexFile(n)) f := filepath.Join(o.repoCacheDir, helmpath.CacheIndexFile(n))
ind, err := repo.LoadIndexFile(f, o.hideValidationWarnings) var ind *repo.IndexFile
if o.hideValidationWarnings {
ind, err = repo.LoadIndexFileHideValidationWarnings(f)
} else {
ind, err = repo.LoadIndexFile(f)
}
if err != nil { if err != nil {
warning("Repo %q is corrupt or missing. Try 'helm repo update'.", n) warning("Repo %q is corrupt or missing. Try 'helm repo update'.", n)
warning("%s", err) warning("%s", err)
@ -278,7 +283,7 @@ func compListChartsOfRepo(repoName string, prefix string) []string {
// installed but before the user does a 'helm repo update' to generate the // installed but before the user does a 'helm repo update' to generate the
// first cached charts file. // first cached charts file.
path = filepath.Join(settings.RepositoryCache, helmpath.CacheIndexFile(repoName)) path = filepath.Join(settings.RepositoryCache, helmpath.CacheIndexFile(repoName))
if indexFile, err := repo.LoadIndexFile(path, false); err == nil { if indexFile, err := repo.LoadIndexFile(path); err == nil {
for name := range indexFile.Entries { for name := range indexFile.Entries {
fullName := fmt.Sprintf("%s/%s", repoName, name) fullName := fmt.Sprintf("%s/%s", repoName, name)
if strings.HasPrefix(fullName, prefix) { if strings.HasPrefix(fullName, prefix) {

@ -113,7 +113,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
var ok bool var ok bool
found := true found := true
if !strings.HasPrefix(d.Repository, "oci://") { if !strings.HasPrefix(d.Repository, "oci://") {
repoIndex, err := repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)), false) repoIndex, err := repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)))
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName) return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName)
} }

@ -230,7 +230,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er
// Next, we need to load the index, and actually look up the chart. // Next, we need to load the index, and actually look up the chart.
idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name))
i, err := repo.LoadIndexFile(idxFile, false) i, err := repo.LoadIndexFile(idxFile)
if err != nil { if err != nil {
return u, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") return u, errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
} }
@ -347,7 +347,7 @@ func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry,
} }
idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name))
i, err := repo.LoadIndexFile(idxFile, false) i, err := repo.LoadIndexFile(idxFile)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
} }

@ -652,7 +652,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
} }
wg.Add(1) wg.Add(1)
go func(r *repo.ChartRepository) { go func(r *repo.ChartRepository) {
if _, err := r.DownloadIndexFile(false); err != nil { if _, err := r.DownloadIndexFile(); err != nil {
// For those dependencies that are not known to helm and using a // For those dependencies that are not known to helm and using a
// generated key name we display the repo url. // generated key name we display the repo url.
if strings.HasPrefix(r.Config.Name, managerKeyPrefix) { if strings.HasPrefix(r.Config.Name, managerKeyPrefix) {
@ -795,7 +795,7 @@ func (m *Manager) loadChartRepositories() (map[string]*repo.ChartRepository, err
for _, re := range rf.Repositories { for _, re := range rf.Repositories {
lname := re.Name lname := re.Name
idxFile := filepath.Join(m.RepositoryCache, helmpath.CacheIndexFile(lname)) idxFile := filepath.Join(m.RepositoryCache, helmpath.CacheIndexFile(lname))
index, err := repo.LoadIndexFile(idxFile, false) index, err := repo.LoadIndexFile(idxFile)
if err != nil { if err != nil {
return indices, err return indices, err
} }

@ -99,7 +99,7 @@ func (r *ChartRepository) Load() error {
filepath.Walk(r.Config.Name, func(path string, f os.FileInfo, err error) error { filepath.Walk(r.Config.Name, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() { if !f.IsDir() {
if strings.Contains(f.Name(), "-index.yaml") { if strings.Contains(f.Name(), "-index.yaml") {
i, err := LoadIndexFile(path, false) i, err := LoadIndexFile(path)
if err != nil { if err != nil {
return err return err
} }
@ -114,7 +114,24 @@ func (r *ChartRepository) Load() error {
} }
// DownloadIndexFile fetches the index from a repository. // DownloadIndexFile fetches the index from a repository.
func (r *ChartRepository) DownloadIndexFile(hideValidationWarnings bool) (string, error) { func (r *ChartRepository) DownloadIndexFile() (string, error) {
return r.downloadIndexFile(false)
}
func (r *ChartRepository) DownloadIndexFileHideValidationWarnings() (string, error) {
return r.downloadIndexFile(true)
}
// Index generates an index for the chart repository and writes an index.yaml file.
func (r *ChartRepository) Index() error {
err := r.generateIndex()
if err != nil {
return err
}
return r.saveIndexFile()
}
func (r *ChartRepository) downloadIndexFile(hideValidationWarnings bool) (string, error) {
parsedURL, err := url.Parse(r.Config.URL) parsedURL, err := url.Parse(r.Config.URL)
if err != nil { if err != nil {
return "", err return "", err
@ -159,15 +176,6 @@ func (r *ChartRepository) DownloadIndexFile(hideValidationWarnings bool) (string
return fname, 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.
func (r *ChartRepository) Index() error {
err := r.generateIndex()
if err != nil {
return err
}
return r.saveIndexFile()
}
func (r *ChartRepository) saveIndexFile() error { func (r *ChartRepository) saveIndexFile() error {
index, err := yaml.Marshal(r.IndexFile) index, err := yaml.Marshal(r.IndexFile)
if err != nil { if err != nil {
@ -237,13 +245,13 @@ func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartV
if err != nil { if err != nil {
return "", err return "", err
} }
idx, err := r.DownloadIndexFile(false) idx, err := r.DownloadIndexFile()
if err != nil { if err != nil {
return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL) return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL)
} }
// Read the index file for the repository to get chart information and return chart URL // Read the index file for the repository to get chart information and return chart URL
repoIndex, err := LoadIndexFile(idx, false) repoIndex, err := LoadIndexFile(idx)
if err != nil { if err != nil {
return "", err return "", err
} }

@ -93,7 +93,7 @@ func TestIndex(t *testing.T) {
} }
tempIndexPath := filepath.Join(testRepository, indexPath) tempIndexPath := filepath.Join(testRepository, indexPath)
actual, err := LoadIndexFile(tempIndexPath, false) actual, err := LoadIndexFile(tempIndexPath)
defer os.Remove(tempIndexPath) // clean up defer os.Remove(tempIndexPath) // clean up
if err != nil { if err != nil {
t.Errorf("Error loading index file %v", err) t.Errorf("Error loading index file %v", err)
@ -105,7 +105,7 @@ func TestIndex(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Error performing re-index: %s\n", err) t.Errorf("Error performing re-index: %s\n", err)
} }
second, err := LoadIndexFile(tempIndexPath, false) second, err := LoadIndexFile(tempIndexPath)
if err != nil { if err != nil {
t.Errorf("Error re-loading index file %v", err) t.Errorf("Error re-loading index file %v", err)
} }
@ -156,7 +156,7 @@ func TestIndexCustomSchemeDownload(t *testing.T) {
} }
defer os.Remove(tempIndexFile.Name()) defer os.Remove(tempIndexFile.Name())
idx, err := repo.DownloadIndexFile(false) idx, err := repo.DownloadIndexFile()
if err != nil { if err != nil {
t.Fatalf("Failed to download index file to %s: %v", idx, err) t.Fatalf("Failed to download index file to %s: %v", idx, err)
} }

@ -101,12 +101,25 @@ func NewIndexFile() *IndexFile {
} }
// LoadIndexFile takes a file at the given path and returns an IndexFile object // LoadIndexFile takes a file at the given path and returns an IndexFile object
func LoadIndexFile(path string, hideValidationWarnings bool) (*IndexFile, error) { func LoadIndexFile(path string) (*IndexFile, error) {
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
i, err := loadIndex(b, path, hideValidationWarnings) i, err := loadIndex(b, path, false)
if err != nil {
return nil, errors.Wrapf(err, "error loading %s", path)
}
return i, nil
}
// LoadIndexFile takes a file at the given path and returns an IndexFile object
func LoadIndexFileHideValidationWarnings(path string) (*IndexFile, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
i, err := loadIndex(b, path, true)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error loading %s", path) return nil, errors.Wrapf(err, "error loading %s", path)
} }

@ -136,7 +136,7 @@ func TestLoadIndex(t *testing.T) {
tc := tc tc := tc
t.Run(tc.Name, func(t *testing.T) { t.Run(tc.Name, func(t *testing.T) {
t.Parallel() t.Parallel()
i, err := LoadIndexFile(tc.Filename, false) i, err := LoadIndexFile(tc.Filename)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -153,7 +153,7 @@ func TestLoadIndex_Duplicates(t *testing.T) {
} }
func TestLoadIndexFileAnnotations(t *testing.T) { func TestLoadIndexFileAnnotations(t *testing.T) {
i, err := LoadIndexFile(annotationstestfile, false) i, err := LoadIndexFile(annotationstestfile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -168,7 +168,7 @@ func TestLoadIndexFileAnnotations(t *testing.T) {
} }
func TestLoadUnorderedIndex(t *testing.T) { func TestLoadUnorderedIndex(t *testing.T) {
i, err := LoadIndexFile(unorderedTestfile, false) i, err := LoadIndexFile(unorderedTestfile)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -230,7 +230,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepo, err) t.Errorf("Problem creating chart repository from %s: %v", testRepo, err)
} }
idx, err := r.DownloadIndexFile(false) idx, err := r.DownloadIndexFile()
if err != nil { if err != nil {
t.Fatalf("Failed to download index file to %s: %#v", idx, err) t.Fatalf("Failed to download index file to %s: %#v", idx, err)
} }
@ -239,7 +239,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Fatalf("error finding created index file: %#v", err) t.Fatalf("error finding created index file: %#v", err)
} }
i, err := LoadIndexFile(idx, false) i, err := LoadIndexFile(idx)
if err != nil { if err != nil {
t.Fatalf("Index %q failed to parse: %s", testfile, err) t.Fatalf("Index %q failed to parse: %s", testfile, err)
} }
@ -283,7 +283,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepo, err) t.Errorf("Problem creating chart repository from %s: %v", testRepo, err)
} }
idx, err := r.DownloadIndexFile(false) idx, err := r.DownloadIndexFile()
if err != nil { if err != nil {
t.Fatalf("Failed to download index file to %s: %#v", idx, err) t.Fatalf("Failed to download index file to %s: %#v", idx, err)
} }
@ -292,7 +292,7 @@ func TestDownloadIndexFile(t *testing.T) {
t.Fatalf("error finding created index file: %#v", err) t.Fatalf("error finding created index file: %#v", err)
} }
i, err := LoadIndexFile(idx, false) i, err := LoadIndexFile(idx)
if err != nil { if err != nil {
t.Fatalf("Index %q failed to parse: %s", testfile, err) t.Fatalf("Index %q failed to parse: %s", testfile, err)
} }

Loading…
Cancel
Save