Merge pull request #13119 from idsulik/update-charts-data-race-fix

pull/12888/merge
Scott Rigby 6 months ago committed by GitHub
commit af4f7370cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -111,20 +111,30 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
func updateCharts(repos []*repo.ChartRepository, 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...") fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var wg sync.WaitGroup var wg sync.WaitGroup
var repoFailList []string failRepoURLChan := make(chan string, len(repos))
for _, re := range repos { for _, re := range repos {
wg.Add(1) wg.Add(1)
go func(re *repo.ChartRepository) { go func(re *repo.ChartRepository) {
defer wg.Done() defer wg.Done()
if _, err := re.DownloadIndexFile(); err != nil { 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) 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 { } 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)
} }
}(re) }(re)
} }
wg.Wait()
go func() {
wg.Wait()
close(failRepoURLChan)
}()
var repoFailList []string
for url := range failRepoURLChan {
repoFailList = append(repoFailList, url)
}
if len(repoFailList) > 0 { if len(repoFailList) > 0 {
return fmt.Errorf("Failed to update the following repositories: %s", return fmt.Errorf("Failed to update the following repositories: %s",

@ -172,7 +172,14 @@ func TestUpdateChartsFailWithError(t *testing.T) {
defer ts.Stop() defer ts.Stop()
var invalidURL = ts.URL() + "55" 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", Name: "charts",
URL: invalidURL, URL: invalidURL,
}, getter.All(settings)) }, getter.All(settings))
@ -181,7 +188,7 @@ func TestUpdateChartsFailWithError(t *testing.T) {
} }
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
err = updateCharts([]*repo.ChartRepository{r}, b) err = updateCharts([]*repo.ChartRepository{r1, r2}, b)
if err == nil { if err == nil {
t.Error("Repo update should return error because update of repository fails and 'fail-on-repo-update-fail' flag set") t.Error("Repo update should return error because update of repository fails and 'fail-on-repo-update-fail' flag set")
return return

Loading…
Cancel
Save