pull/30976/merge
Kerat 4 days ago committed by GitHub
commit 7bf56a615b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -108,6 +108,10 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
}
repoName := repoNames[d.Name]
if d.Alias != "" {
repoName = repoNames[d.Alias]
}
// if the repository was not defined, but the dependency defines a repository url, bypass the cache
if repoName == "" && d.Repository != "" {
locked[i] = &chart.Dependency{

@ -137,9 +137,22 @@ func TestResolve(t *testing.T) {
},
err: true,
},
{
name: "charts with same name but different repo",
req: []*chart.Dependency{
{Name: "alpine", Repository: "repository-1", Version: "0.1.0"},
{Name: "alpine", Repository: "repository-2", Version: "0.3.0", Alias: "alpine-alias"},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "alpine", Repository: "repository-1", Version: "0.1.0"},
{Name: "alpine", Repository: "repository-2", Version: "0.3.0"},
},
},
},
}
repoNames := map[string]string{"alpine": "kubernetes-charts", "redis": "kubernetes-charts"}
repoNames := map[string]string{"alpine": "repository-1", "redis": "repository-1", "alpine-alias": "repository-2"}
registryClient, _ := registry.NewClient()
r := New("testdata/chartpath", "testdata/repository", registryClient)
for _, tt := range tests {

@ -0,0 +1,16 @@
apiVersion: v1
entries:
alpine:
- name: alpine
urls:
- https://charts.helm.sh/stable/alpine-0.1.0.tgz
checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d
home: https://helm.sh/helm
sources:
- https://github.com/helm/helm
version: 0.3.0
description: Deploy a basic Alpine Linux pod
keywords: []
maintainers: []
icon: ""
apiVersion: v2

@ -144,7 +144,11 @@ func (md *Metadata) Validate() error {
key = dependency.Alias
}
if dependencies[key] != nil {
return ValidationErrorf("more than one dependency with name or alias %q", key)
return ValidationErrorf(
"more than one dependency with name or alias %q. "+
"Try using distinct aliases for dependencies with the same chart name.",
key,
)
}
dependencies[key] = dependency
}

@ -99,7 +99,7 @@ func TestValidate(t *testing.T) {
{Name: "foo", Alias: ""},
},
},
ValidationError("more than one dependency with name or alias \"foo\""),
ValidationError("more than one dependency with name or alias \"foo\". Try using distinct aliases for dependencies with the same chart name."),
},
{
"two dependencies with alias from second dependency shadowing first one",
@ -113,7 +113,7 @@ func TestValidate(t *testing.T) {
{Name: "bar", Alias: "foo"},
},
},
ValidationError("more than one dependency with name or alias \"foo\""),
ValidationError("more than one dependency with name or alias \"foo\". Try using distinct aliases for dependencies with the same chart name."),
},
{
// this case would make sense and could work in future versions of Helm, currently template rendering would
@ -129,7 +129,7 @@ func TestValidate(t *testing.T) {
{Name: "foo", Alias: "", Version: "1.0.0"},
},
},
ValidationError("more than one dependency with name or alias \"foo\""),
ValidationError("more than one dependency with name or alias \"foo\". Try using distinct aliases for dependencies with the same chart name."),
},
{
// this case would make sense and could work in future versions of Helm, currently template rendering would
@ -145,7 +145,7 @@ func TestValidate(t *testing.T) {
{Name: "foo", Repository: "repo-1"},
},
},
ValidationError("more than one dependency with name or alias \"foo\""),
ValidationError("more than one dependency with name or alias \"foo\". Try using distinct aliases for dependencies with the same chart name."),
},
{
"dependencies has nil",

@ -506,6 +506,10 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
var ru []*repo.Entry
for _, dd := range deps {
chartName := dd.Name
if dd.Alias != "" {
chartName = dd.Alias
}
// If the chart is in the local charts directory no repository needs
// to be specified.
@ -514,7 +518,7 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
}
// When the repoName for a dependency is known we can skip ensuring
if _, ok := repoNames[dd.Name]; ok {
if _, ok := repoNames[chartName]; ok {
continue
}
@ -530,7 +534,7 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
}
rn = managerKeyPrefix + rn
repoNames[dd.Name] = rn
repoNames[chartName] = rn
// Assuming the repository is generally available. For Helm managed
// access controls the repository needs to be added through the user
@ -576,6 +580,10 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string,
// by Helm.
missing := []string{}
for _, dd := range deps {
chartName := dd.Name
if dd.Alias != "" {
chartName = dd.Alias
}
// Don't map the repository, we don't need to download chart from charts directory
if dd.Repository == "" {
continue
@ -589,12 +597,12 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string,
if m.Debug {
fmt.Fprintf(m.Out, "Repository from local path: %s\n", dd.Repository)
}
reposMap[dd.Name] = dd.Repository
reposMap[chartName] = dd.Repository
continue
}
if registry.IsOCI(dd.Repository) {
reposMap[dd.Name] = dd.Repository
reposMap[chartName] = dd.Repository
continue
}
@ -605,11 +613,11 @@ func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string,
(strings.HasPrefix(dd.Repository, "alias:") && strings.TrimPrefix(dd.Repository, "alias:") == repo.Name) {
found = true
dd.Repository = repo.URL
reposMap[dd.Name] = repo.Name
reposMap[chartName] = repo.Name
break
} else if urlutil.Equal(repo.URL, dd.Repository) {
found = true
reposMap[dd.Name] = repo.Name
reposMap[chartName] = repo.Name
break
}
}

Loading…
Cancel
Save