Resolve resolves dependencies and returns a lock file with the resolution.
(reqs []*chart.Dependency, repoNames map[string]string)
| 54 | |
| 55 | // Resolve resolves dependencies and returns a lock file with the resolution. |
| 56 | func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string) (*chart.Lock, error) { |
| 57 | |
| 58 | // Now we clone the dependencies, locking as we go. |
| 59 | locked := make([]*chart.Dependency, len(reqs)) |
| 60 | missing := []string{} |
| 61 | for i, d := range reqs { |
| 62 | constraint, err := semver.NewConstraint(d.Version) |
| 63 | if err != nil { |
| 64 | return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %w", d.Name, err) |
| 65 | } |
| 66 | |
| 67 | if d.Repository == "" { |
| 68 | // Local chart subfolder |
| 69 | if _, err := GetLocalPath(filepath.Join("charts", d.Name), r.chartpath); err != nil { |
| 70 | return nil, err |
| 71 | } |
| 72 | |
| 73 | locked[i] = &chart.Dependency{ |
| 74 | Name: d.Name, |
| 75 | Repository: "", |
| 76 | Version: d.Version, |
| 77 | } |
| 78 | continue |
| 79 | } |
| 80 | if strings.HasPrefix(d.Repository, "file://") { |
| 81 | chartpath, err := GetLocalPath(d.Repository, r.chartpath) |
| 82 | if err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | |
| 86 | ch, err := loader.LoadDir(chartpath) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | |
| 91 | v, err := semver.NewVersion(ch.Metadata.Version) |
| 92 | if err != nil { |
| 93 | // Not a legit entry. |
| 94 | continue |
| 95 | } |
| 96 | |
| 97 | if !constraint.Check(v) { |
| 98 | missing = append(missing, fmt.Sprintf("%q (repository %q, version %q)", d.Name, d.Repository, d.Version)) |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | locked[i] = &chart.Dependency{ |
| 103 | Name: d.Name, |
| 104 | Repository: d.Repository, |
| 105 | Version: ch.Metadata.Version, |
| 106 | } |
| 107 | continue |
| 108 | } |
| 109 | |
| 110 | repoName := repoNames[d.Name] |
| 111 | // if the repository was not defined, but the dependency defines a repository url, bypass the cache |
| 112 | if repoName == "" && d.Repository != "" { |
| 113 | locked[i] = &chart.Dependency{ |