Allow dependency build to add/resolve repo

fixes https://github.com/helm/helm/issues/7214
The main issue was due to dependency build not adding the
repo causing the command to fail. The ideal response should be
to add the repo and then continue with the command,
something that dependency update does.

The functionality has been exported and then shared between
dependency build and update as a method.

Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
pull/7242/head
Vibhav Bobade 6 years ago
parent 512544b9ab
commit 436d013f94

@ -113,3 +113,15 @@ func TestDependencyBuildCmdWithHelmV2Hash(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestDependencyBuildCmdWithUnavailableRepos(t *testing.T) {
chartName := "testdata/testcharts/issue-7214"
cmd := fmt.Sprintf("dependency build '%s'", chartName)
_, out, err := executeActionCommand(cmd)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
}
}

@ -95,7 +95,13 @@ func (m *Manager) Build() error {
} }
} }
if _, err := m.resolveRepoNames(req); err != nil { repoNames, err := m.resolveRepoNames(req)
if err != nil {
return err
}
lock, done, err := m.resolveChartRepos(req, repoNames, c)
if done {
return err return err
} }
@ -161,33 +167,40 @@ func (m *Manager) Update() error {
} }
} }
// Now we need to find out which version of a chart best satisfies the lock, done, err := m.resolveChartRepos(req, repoNames, c)
if done {
return err
}
// Finally, we need to write the lockfile.
return writeLock(m.ChartPath, lock, c.Metadata.APIVersion == chart.APIVersionV1)
}
// resolveChartRepos resolves the Chart Repos and add them if they are not present
func (m *Manager) resolveChartRepos(req []*chart.Dependency, repoNames map[string]string, c *chart.Chart) (*chart.Lock, bool, error) {
// Find out which version of a chart best satisfies the
// dependencies in the Chart.yaml // dependencies in the Chart.yaml
lock, err := m.resolve(req, repoNames) lock, err := m.resolve(req, repoNames)
if err != nil { if err != nil {
return err return nil, true, err
} }
// Now we need to fetch every package here into charts/ // Now we need to fetch every package here into charts/
if err := m.downloadAll(lock.Dependencies); err != nil { if err := m.downloadAll(lock.Dependencies); err != nil {
return err return nil, true, err
} }
// downloadAll might overwrite dependency version, recalculate lock digest // downloadAll might overwrite dependency version, recalculate lock digest
newDigest, err := resolver.HashReq(req, lock.Dependencies) newDigest, err := resolver.HashReq(req, lock.Dependencies)
if err != nil { if err != nil {
return err return nil, true, err
} }
lock.Digest = newDigest lock.Digest = newDigest
// If the lock file hasn't changed, don't write a new one. // If the lock file hasn't changed, don't write a new one.
oldLock := c.Lock oldLock := c.Lock
if oldLock != nil && oldLock.Digest == lock.Digest { if oldLock != nil && oldLock.Digest == lock.Digest {
return nil return nil, true, nil
} }
return lock, false, nil
// Finally, we need to write the lockfile.
return writeLock(m.ChartPath, lock, c.Metadata.APIVersion == chart.APIVersionV1)
} }
func (m *Manager) loadChartDir() (*chart.Chart, error) { func (m *Manager) loadChartDir() (*chart.Chart, error) {

Loading…
Cancel
Save