pull/10096/merge
Felipe Santos 1 day ago committed by GitHub
commit efd34b94f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -59,24 +59,45 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
locked := make([]*chart.Dependency, len(reqs)) locked := make([]*chart.Dependency, len(reqs))
missing := []string{} missing := []string{}
for i, d := range reqs { for i, d := range reqs {
constraint, err := semver.NewConstraint(d.Version) var constraint *semver.Constraints
// Validate version early if set, regardless of local or remote
if d.Version != "" {
var err error
constraint, err = semver.NewConstraint(d.Version)
if err != nil { if err != nil {
return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %w", d.Name, err) return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %w", d.Name, err)
} }
}
// Handle local chart dependencies (empty repository)
if d.Repository == "" { if d.Repository == "" {
// Local chart subfolder chartpath, err := GetLocalPath(filepath.Join("charts", d.Name), r.chartpath)
if _, err := GetLocalPath(filepath.Join("charts", d.Name), r.chartpath); err != nil { if err != nil {
return nil, err
}
version := d.Version
// Determine version from local chart if not specified
if version == "" {
ch, err := loader.LoadDir(chartpath)
if err != nil {
return nil, err return nil, err
} }
version = ch.Metadata.Version
}
locked[i] = &chart.Dependency{ locked[i] = &chart.Dependency{
Name: d.Name, Name: d.Name,
Repository: "", Repository: "",
Version: d.Version, Version: version,
} }
continue continue
} }
// Handle file:// repository dependencies
if strings.HasPrefix(d.Repository, "file://") { if strings.HasPrefix(d.Repository, "file://") {
chartpath, err := GetLocalPath(d.Repository, r.chartpath) chartpath, err := GetLocalPath(d.Repository, r.chartpath)
if err != nil { if err != nil {
@ -90,14 +111,20 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
v, err := semver.NewVersion(ch.Metadata.Version) v, err := semver.NewVersion(ch.Metadata.Version)
if err != nil { if err != nil {
// Not a legit entry. // If no version specified, add to missing list
if d.Version == "" {
missing = append(missing, fmt.Sprintf("%q (repository %q)", d.Name, d.Repository))
}
continue continue
} }
// If version is specified, validate it against the local chart
if d.Version != "" {
if !constraint.Check(v) { if !constraint.Check(v) {
missing = append(missing, fmt.Sprintf("%q (repository %q, version %q)", d.Name, d.Repository, d.Version)) missing = append(missing, fmt.Sprintf("%q (repository %q, version %q)", d.Name, d.Repository, d.Version))
continue continue
} }
}
locked[i] = &chart.Dependency{ locked[i] = &chart.Dependency{
Name: d.Name, Name: d.Name,

@ -137,6 +137,28 @@ func TestResolve(t *testing.T) {
}, },
err: true, err: true,
}, },
{
name: "no version set for local chart under charts path",
req: []*chart.Dependency{
{Name: "localdependency", Repository: "", Version: ""},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "localdependency", Repository: "", Version: "0.1.0"},
},
},
},
{
name: "no version set for local chart from file://",
req: []*chart.Dependency{
{Name: "localdependency", Repository: "file://base", Version: ""},
},
expect: &chart.Lock{
Dependencies: []*chart.Dependency{
{Name: "localdependency", Repository: "file://base", Version: "0.1.0"},
},
},
},
} }
repoNames := map[string]string{"alpine": "kubernetes-charts", "redis": "kubernetes-charts"} repoNames := map[string]string{"alpine": "kubernetes-charts", "redis": "kubernetes-charts"}

@ -70,8 +70,8 @@ the dependency charts stored locally. The path should start with a prefix of
repository: "file://../dependency_chart/nginx" repository: "file://../dependency_chart/nginx"
If the dependency chart is retrieved locally, it is not required to have the If the dependency chart is retrieved locally, it is not required to have the
repository added to helm by "helm add repo". Version matching is also supported repository added to helm by "helm add repo". Version matching is optionally
for this case. supported for this case.
` `
const dependencyListDesc = ` const dependencyListDesc = `

Loading…
Cancel
Save