refactor: simplify pull channel from #1706 (#1707)

This commit is contained in:
Thomas Loubiou 2021-03-09 02:16:04 +01:00 committed by GitHub
parent 3215eaf710
commit bf9f36b2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 14 deletions

View File

@ -972,9 +972,9 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
}
var builds []*chartPrepareResult
pullChan := make(chan *PullCommand)
pullChan := make(chan PullCommand)
defer func() {
pullChan <- nil
close(pullChan)
}()
go st.pullChartWorker(pullChan, helm)
@ -3020,7 +3020,7 @@ func (st *HelmState) Reverse() {
}
}
func (st *HelmState) getOCIChart(pullChan chan *PullCommand, release *ReleaseSpec, tempDir string, helm helmexec.Interface) (*string, error) {
func (st *HelmState) getOCIChart(pullChan chan PullCommand, release *ReleaseSpec, tempDir string, helm helmexec.Interface) (*string, error) {
repo, name := st.GetRepositoryAndNameFromChartName(release.Chart)
if repo == nil {
return nil, nil
@ -3070,22 +3070,17 @@ func (st *HelmState) getOCIChart(pullChan chan *PullCommand, release *ReleaseSpe
}
// Pull charts one by one to prevent concurrent pull problems with Helm
func (st *HelmState) pullChartWorker(pullChan chan *PullCommand, helm helmexec.Interface) {
for {
pullCmd := <-pullChan
if pullCmd != nil {
err := helm.ChartPull(pullCmd.ChartRef)
pullCmd.responseChan <- err
} else {
return
}
func (st *HelmState) pullChartWorker(pullChan chan PullCommand, helm helmexec.Interface) {
for pullCmd := range pullChan {
err := helm.ChartPull(pullCmd.ChartRef)
pullCmd.responseChan <- err
}
}
// Send a pull command to the pull worker
func (st *HelmState) pullChart(pullChan chan *PullCommand, chartRef string) error {
func (st *HelmState) pullChart(pullChan chan PullCommand, chartRef string) error {
response := make(chan error, 1)
cmd := &PullCommand{
cmd := PullCommand{
responseChan: response,
ChartRef: chartRef,
}