mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #13119 from idsulik/update-charts-data-race-fix
This commit is contained in:
commit
af4f7370cb
2 changed files with 22 additions and 5 deletions
|
|
@ -111,20 +111,30 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
|
|||
func updateCharts(repos []*repo.ChartRepository, out io.Writer) error {
|
||||
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
|
||||
var wg sync.WaitGroup
|
||||
var repoFailList []string
|
||||
failRepoURLChan := make(chan string, len(repos))
|
||||
|
||||
for _, re := range repos {
|
||||
wg.Add(1)
|
||||
go func(re *repo.ChartRepository) {
|
||||
defer wg.Done()
|
||||
if _, err := re.DownloadIndexFile(); err != nil {
|
||||
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)
|
||||
repoFailList = append(repoFailList, re.Config.URL)
|
||||
failRepoURLChan <- re.Config.URL
|
||||
} else {
|
||||
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name)
|
||||
}
|
||||
}(re)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(failRepoURLChan)
|
||||
}()
|
||||
|
||||
var repoFailList []string
|
||||
for url := range failRepoURLChan {
|
||||
repoFailList = append(repoFailList, url)
|
||||
}
|
||||
|
||||
if len(repoFailList) > 0 {
|
||||
return fmt.Errorf("Failed to update the following repositories: %s",
|
||||
|
|
|
|||
|
|
@ -172,7 +172,14 @@ func TestUpdateChartsFailWithError(t *testing.T) {
|
|||
defer ts.Stop()
|
||||
|
||||
var invalidURL = ts.URL() + "55"
|
||||
r, err := repo.NewChartRepository(&repo.Entry{
|
||||
r1, err := repo.NewChartRepository(&repo.Entry{
|
||||
Name: "charts",
|
||||
URL: invalidURL,
|
||||
}, getter.All(settings))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
r2, err := repo.NewChartRepository(&repo.Entry{
|
||||
Name: "charts",
|
||||
URL: invalidURL,
|
||||
}, getter.All(settings))
|
||||
|
|
@ -181,7 +188,7 @@ func TestUpdateChartsFailWithError(t *testing.T) {
|
|||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
err = updateCharts([]*repo.ChartRepository{r}, b)
|
||||
err = updateCharts([]*repo.ChartRepository{r1, r2}, b)
|
||||
if err == nil {
|
||||
t.Error("Repo update should return error because update of repository fails and 'fail-on-repo-update-fail' flag set")
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue