From 436d013f9457cbc392367daedd336e953479879e Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Sun, 12 Apr 2020 01:22:14 +0530 Subject: [PATCH] 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 --- cmd/helm/dependency_build_test.go | 12 ++++++++++ pkg/downloader/manager.go | 37 +++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/cmd/helm/dependency_build_test.go b/cmd/helm/dependency_build_test.go index eeca12fa6..e5ec07978 100644 --- a/cmd/helm/dependency_build_test.go +++ b/cmd/helm/dependency_build_test.go @@ -113,3 +113,15 @@ func TestDependencyBuildCmdWithHelmV2Hash(t *testing.T) { 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) + } +} diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 00198de0c..ff0522f16 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -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 } @@ -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 lock, err := m.resolve(req, repoNames) if err != nil { - return err + return nil, true, err } - // Now we need to fetch every package here into charts/ if err := m.downloadAll(lock.Dependencies); err != nil { - return err + return nil, true, err } - // downloadAll might overwrite dependency version, recalculate lock digest newDigest, err := resolver.HashReq(req, lock.Dependencies) if err != nil { - return err + return nil, true, err } lock.Digest = newDigest - // If the lock file hasn't changed, don't write a new one. oldLock := c.Lock if oldLock != nil && oldLock.Digest == lock.Digest { - return nil + return nil, true, nil } - - // Finally, we need to write the lockfile. - return writeLock(m.ChartPath, lock, c.Metadata.APIVersion == chart.APIVersionV1) + return lock, false, nil } func (m *Manager) loadChartDir() (*chart.Chart, error) {