Skip to content

Commit

Permalink
fix(pkg/downloader): resolve repo alias before checking digests on build
Browse files Browse the repository at this point in the history
`Update()` gets repo names before resolving a lock file by calling
`resolveRepoNames(req)`. But that method changes aliased repo URLs into
the actual URLs. That makes digests from `helm update` and `helm build`
be different for each other.

To make them in sync, setting actual (resolved) repo URLs into the
loaded chart during `helm build` is necessary. Thus, this commit adds an
extra step in the `Build()` implementation.

For comments, this commit also changes the name of `getRepoNames()` into
`resolveRepoNames()` to avoid misunderstanding since getters are
expected to not mutate their input data in general.

Signed-off-by: Hang Park <hangpark@kaist.ac.kr>
  • Loading branch information
hangpark committed Nov 12, 2019
1 parent 17553db commit 0987c6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pkg/downloader/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func (m *Manager) Build() error {
return m.Update()
}

// Check that all of the repos we're dependent on actually exist.
req := c.Metadata.Dependencies
if _, err := m.resolveRepoNames(req); err != nil {
return err
}

if sum, err := resolver.HashReq(req, lock.Dependencies); err != nil || sum != lock.Digest {
return errors.New("Chart.lock is out of sync with Chart.yaml")
}
Expand Down Expand Up @@ -120,7 +125,7 @@ func (m *Manager) Update() error {

// Check that all of the repos we're dependent on actually exist and
// the repo index names.
repoNames, err := m.getRepoNames(req)
repoNames, err := m.resolveRepoNames(req)
if err != nil {
return err
}
Expand Down Expand Up @@ -372,8 +377,9 @@ Loop:
return nil
}

// getRepoNames returns the repo names of the referenced deps which can be used to fetch the cahced index file.
func (m *Manager) getRepoNames(deps []*chart.Dependency) (map[string]string, error) {
// resolveRepoNames returns the repo names of the referenced deps which can be used to fetch the cached index file
// and replaces aliased repository URLs into resolved URLs in dependencies.
func (m *Manager) resolveRepoNames(deps []*chart.Dependency) (map[string]string, error) {
rf, err := loadRepoConfig(m.RepositoryConfig)
if err != nil {
if os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestGetRepoNames(t *testing.T) {
}

for _, tt := range tests {
l, err := m.getRepoNames(tt.req)
l, err := m.resolveRepoNames(tt.req)
if err != nil {
if tt.err {
continue
Expand Down

0 comments on commit 0987c6f

Please sign in to comment.