Skip to content

Commit

Permalink
refactor: simplify pull channel from helm#1706 (helm#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
xabufr committed Mar 9, 2021
1 parent 3215eaf commit bf9f36b
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions pkg/state/state.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit bf9f36b

Please sign in to comment.