MCPcopy
hub / github.com/helm/helm / Resolve

Method Resolve

internal/resolver/resolver.go:56–209  ·  view source on GitHub ↗

Resolve resolves dependencies and returns a lock file with the resolution.

(reqs []*chart.Dependency, repoNames map[string]string)

Source from the content-addressed store, hash-verified

54
55// Resolve resolves dependencies and returns a lock file with the resolution.
56func (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{

Callers 1

TestResolveFunction · 0.45

Calls 8

LoadDirFunction · 0.92
IsOCIFunction · 0.92
CacheIndexFileFunction · 0.92
GetLocalPathFunction · 0.85
HashReqFunction · 0.85
NowMethod · 0.80
CheckMethod · 0.45
TagsMethod · 0.45

Tested by 1

TestResolveFunction · 0.36