fix concurrency issue (#742)

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2023-03-15 15:42:16 +08:00 committed by GitHub
parent 2d9f83c1de
commit 063ba86447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -1098,7 +1098,9 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
releases := releasesNeedCharts(selected) releases := releasesNeedCharts(selected)
temp := make(map[PrepareChartKey]string, len(releases)) var prepareChartInfoMutex sync.Mutex
prepareChartInfo := make(map[PrepareChartKey]string, len(releases))
errs := []error{} errs := []error{}
@ -1302,11 +1304,15 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
return return
} }
temp[PrepareChartKey{ func() {
prepareChartInfoMutex.Lock()
defer prepareChartInfoMutex.Unlock()
prepareChartInfo[PrepareChartKey{
Namespace: downloadRes.releaseNamespace, Namespace: downloadRes.releaseNamespace,
KubeContext: downloadRes.releaseContext, KubeContext: downloadRes.releaseContext,
Name: downloadRes.releaseName, Name: downloadRes.releaseName,
}] = downloadRes.chartPath }] = downloadRes.chartPath
}()
if downloadRes.buildDeps { if downloadRes.buildDeps {
builds = append(builds, downloadRes) builds = append(builds, downloadRes)
@ -1325,7 +1331,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
} }
} }
return temp, nil return prepareChartInfo, nil
} }
// nolint: unparam // nolint: unparam