fix(concurrency): add mutex to protect repoFailList and out in updateCharts

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
pull/13119/head
Suleiman Dibirov 2 weeks ago
parent 15f76cf83c
commit 62e7eedb4b

@ -116,15 +116,22 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
func updateCharts(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdateFail bool) error {
fmt.Fprintln(out, "Hang tight while we grab the latest from your chart repositories...")
var wg sync.WaitGroup
var repoFailList []string
var (
wg sync.WaitGroup
mu sync.Mutex
repoFailList []string
)
for _, re := range repos {
wg.Add(1)
go func(re *repo.ChartRepository) {
defer wg.Done()
if _, err := re.DownloadIndexFile(); err != nil {
mu.Lock()
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)
mu.Unlock()
} else {
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name)
}

@ -205,7 +205,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))
@ -214,7 +221,7 @@ func TestUpdateChartsFailWithError(t *testing.T) {
}
b := bytes.NewBuffer(nil)
err = updateCharts([]*repo.ChartRepository{r}, b, true)
err = updateCharts([]*repo.ChartRepository{r1, r2}, b, true)
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…
Cancel
Save