Commit b49f4269 authored by Xiang Dai's avatar Xiang Dai

fix issue when dependency is URL

Signed-off-by: 's avatarXiang Dai <764524258@qq.com>
parent 70af7ba4
...@@ -205,6 +205,11 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, ge ...@@ -205,6 +205,11 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, ge
} }
c.setCredentials(r) c.setCredentials(r)
// Skip if dependency not contain name
if len(r.Config.Name) == 0 {
return u, r.Client, nil
}
// 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.
i, err := repo.LoadIndexFile(c.HelmHome.CacheIndex(r.Config.Name)) i, err := repo.LoadIndexFile(c.HelmHome.CacheIndex(r.Config.Name))
if err != nil { if err != nil {
......
...@@ -233,7 +233,7 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error { ...@@ -233,7 +233,7 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error {
// Any failure to resolve/download a chart should fail: // Any failure to resolve/download a chart should fail:
// https://github.com/kubernetes/helm/issues/1439 // https://github.com/kubernetes/helm/issues/1439
churl, username, password, err := findChartURL(dep.Name, dep.Version, dep.Repository, repos) churl, username, password, err := m.findChartURL(dep.Name, dep.Version, dep.Repository, repos)
if err != nil { if err != nil {
saveError = fmt.Errorf("could not find %s: %s", churl, err) saveError = fmt.Errorf("could not find %s: %s", churl, err)
break break
...@@ -403,9 +403,17 @@ func (m *Manager) getRepoNames(deps []*chartutil.Dependency) (map[string]string, ...@@ -403,9 +403,17 @@ func (m *Manager) getRepoNames(deps []*chartutil.Dependency) (map[string]string,
} }
} }
if !found { if !found {
missing = append(missing, dd.Repository) repository := dd.Repository
// Add if URL
_, err := url.ParseRequestURI(repository)
if err == nil {
reposMap[repository] = repository
continue
} }
missing = append(missing, repository)
} }
}
if len(missing) > 0 { if len(missing) > 0 {
errorMessage := fmt.Sprintf("no repository definition for %s. Please add them via 'helm repo add'", strings.Join(missing, ", ")) errorMessage := fmt.Sprintf("no repository definition for %s. Please add them via 'helm repo add'", strings.Join(missing, ", "))
// It is common for people to try to enter "stable" as a repository instead of the actual URL. // It is common for people to try to enter "stable" as a repository instead of the actual URL.
...@@ -424,6 +432,7 @@ repository, use "https://kubernetes-charts.storage.googleapis.com/" or "@stable" ...@@ -424,6 +432,7 @@ repository, use "https://kubernetes-charts.storage.googleapis.com/" or "@stable"
} }
return nil, errors.New(errorMessage) return nil, errors.New(errorMessage)
} }
return reposMap, nil return reposMap, nil
} }
...@@ -475,7 +484,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error { ...@@ -475,7 +484,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
// repoURL is the repository to search // repoURL is the repository to search
// //
// If it finds a URL that is "relative", it will prepend the repoURL. // If it finds a URL that is "relative", it will prepend the repoURL.
func findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRepository) (url, username, password string, err error) { func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRepository) (url, username, password string, err error) {
for _, cr := range repos { for _, cr := range repos {
if urlutil.Equal(repoURL, cr.Config.URL) { if urlutil.Equal(repoURL, cr.Config.URL) {
var entry repo.ChartVersions var entry repo.ChartVersions
...@@ -497,6 +506,10 @@ func findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRep ...@@ -497,6 +506,10 @@ func findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRep
return return
} }
} }
url, err = repo.FindChartInRepoURL(repoURL, name, version, "", "", "", m.Getters)
if err == nil {
return
}
err = fmt.Errorf("chart %s not found in %s", name, repoURL) err = fmt.Errorf("chart %s not found in %s", name, repoURL)
return return
} }
......
...@@ -78,7 +78,7 @@ func TestFindChartURL(t *testing.T) { ...@@ -78,7 +78,7 @@ func TestFindChartURL(t *testing.T) {
version := "0.1.0" version := "0.1.0"
repoURL := "http://example.com/charts" repoURL := "http://example.com/charts"
churl, username, password, err := findChartURL(name, version, repoURL, repos) churl, username, password, err := m.findChartURL(name, version, repoURL, repos)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -106,13 +106,6 @@ func TestGetRepoNames(t *testing.T) { ...@@ -106,13 +106,6 @@ func TestGetRepoNames(t *testing.T) {
err bool err bool
expectedErr string expectedErr string
}{ }{
{
name: "no repo definition failure",
req: []*chartutil.Dependency{
{Name: "oedipus-rex", Repository: "http://example.com/test"},
},
err: true,
},
{ {
name: "no repo definition failure -- stable repo", name: "no repo definition failure -- stable repo",
req: []*chartutil.Dependency{ req: []*chartutil.Dependency{
...@@ -128,6 +121,13 @@ func TestGetRepoNames(t *testing.T) { ...@@ -128,6 +121,13 @@ func TestGetRepoNames(t *testing.T) {
err: true, err: true,
expectedErr: "no 'repository' field specified for dependency: \"dependency-missing-repository-field\"", expectedErr: "no 'repository' field specified for dependency: \"dependency-missing-repository-field\"",
}, },
{
name: "dependency repository is url but not exist in repos",
req: []*chartutil.Dependency{
{Name: "oedipus-rex", Repository: "http://example.com/test"},
},
expect: map[string]string{"http://example.com/test": "http://example.com/test"},
},
{ {
name: "no repo definition failure", name: "no repo definition failure",
req: []*chartutil.Dependency{ req: []*chartutil.Dependency{
......
...@@ -71,7 +71,18 @@ func (r *Resolver) Resolve(reqs *chartutil.Requirements, repoNames map[string]st ...@@ -71,7 +71,18 @@ func (r *Resolver) Resolve(reqs *chartutil.Requirements, repoNames map[string]st
return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %s", d.Name, err) return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %s", d.Name, err)
} }
repoIndex, err := repo.LoadIndexFile(r.helmhome.CacheIndex(repoNames[d.Name])) // repo does not exist in cache but has url info
cacheRepoName := repoNames[d.Name]
if cacheRepoName == "" && d.Repository != "" {
locked[i] = &chartutil.Dependency{
Name: d.Name,
Repository: d.Repository,
Version: d.Version,
}
continue
}
repoIndex, err := repo.LoadIndexFile(r.helmhome.CacheIndex(cacheRepoName))
if err != nil { if err != nil {
return nil, fmt.Errorf("no cached repo found. (try 'helm repo update'). %s", err) return nil, fmt.Errorf("no cached repo found. (try 'helm repo update'). %s", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment