Fail on failed chart repository update

pull/4348/head
l.aminov 7 years ago
parent 50ca1b5bb5
commit 3f7231f035

@ -40,7 +40,7 @@ future releases.
var errNoRepositories = errors.New("no repositories found. You must add one before updating") var errNoRepositories = errors.New("no repositories found. You must add one before updating")
type repoUpdateCmd struct { type repoUpdateCmd struct {
update func([]*repo.ChartRepository, io.Writer, helmpath.Home) update func([]*repo.ChartRepository, io.Writer, helmpath.Home) error
home helmpath.Home home helmpath.Home
out io.Writer out io.Writer
} }
@ -80,14 +80,15 @@ func (u *repoUpdateCmd) run() error {
} }
repos = append(repos, r) repos = append(repos, r)
} }
return u.update(repos, u.out, u.home)
u.update(repos, u.out, u.home)
return nil
} }
func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Home) { func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Home) error {
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...") fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var wg sync.WaitGroup var (
errorCounter int
wg sync.WaitGroup
)
for _, re := range repos { for _, re := range repos {
wg.Add(1) wg.Add(1)
go func(re *repo.ChartRepository) { go func(re *repo.ChartRepository) {
@ -98,6 +99,7 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Ho
} }
err := re.DownloadIndexFile(home.Cache()) err := re.DownloadIndexFile(home.Cache())
if err != nil { if err != nil {
errorCounter++
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err) fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err)
} else { } else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name) fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name)
@ -105,5 +107,9 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Ho
}(re) }(re)
} }
wg.Wait() wg.Wait()
if errorCounter != 0 {
return errors.New("Update Failed. Check log for details")
}
fmt.Fprintln(out, "Update Complete. ⎈ Happy Helming!⎈ ") fmt.Fprintln(out, "Update Complete. ⎈ Happy Helming!⎈ ")
return nil
} }

@ -445,7 +445,10 @@ func (m *Manager) UpdateRepositories() error {
func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error { func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
out := m.Out out := m.Out
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...") fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var wg sync.WaitGroup var (
errorCounter int
wg sync.WaitGroup
)
for _, c := range repos { for _, c := range repos {
r, err := repo.NewChartRepository(c, m.Getters) r, err := repo.NewChartRepository(c, m.Getters)
if err != nil { if err != nil {
@ -454,6 +457,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
wg.Add(1) wg.Add(1)
go func(r *repo.ChartRepository) { go func(r *repo.ChartRepository) {
if err := r.DownloadIndexFile(m.HelmHome.Cache()); err != nil { if err := r.DownloadIndexFile(m.HelmHome.Cache()); err != nil {
errorCounter++
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err) fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", r.Config.Name, r.Config.URL, err)
} else { } else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", r.Config.Name) fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", r.Config.Name)
@ -462,6 +466,9 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
}(r) }(r)
} }
wg.Wait() wg.Wait()
if errorCounter != 0 {
return errors.New("Update Failed. Check log for details")
}
fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈")
return nil return nil
} }

Loading…
Cancel
Save