fix: pull OCI charts one by one (#1706)
* fix: pull OCI charts one by one * fix: gofmt
This commit is contained in:
parent
19cbea49f7
commit
453b498ccb
|
|
@ -73,6 +73,11 @@ type ReleaseSetSpec struct {
|
||||||
MissingFileHandler string `yaml:"missingFileHandler,omitempty"`
|
MissingFileHandler string `yaml:"missingFileHandler,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PullCommand struct {
|
||||||
|
ChartRef string
|
||||||
|
responseChan chan error
|
||||||
|
}
|
||||||
|
|
||||||
// HelmState structure for the helmfile
|
// HelmState structure for the helmfile
|
||||||
type HelmState struct {
|
type HelmState struct {
|
||||||
basePath string
|
basePath string
|
||||||
|
|
@ -961,6 +966,11 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
|
||||||
}
|
}
|
||||||
|
|
||||||
var builds []*chartPrepareResult
|
var builds []*chartPrepareResult
|
||||||
|
pullChan := make(chan *PullCommand)
|
||||||
|
defer func() {
|
||||||
|
pullChan <- nil
|
||||||
|
}()
|
||||||
|
go st.pullChartWorker(pullChan, helm)
|
||||||
|
|
||||||
st.scatterGather(
|
st.scatterGather(
|
||||||
concurrency,
|
concurrency,
|
||||||
|
|
@ -993,7 +1003,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
|
||||||
chartFetchedByGoGetter := chartPath != chartName
|
chartFetchedByGoGetter := chartPath != chartName
|
||||||
|
|
||||||
if !chartFetchedByGoGetter {
|
if !chartFetchedByGoGetter {
|
||||||
ociChartPath, err := st.getOCIChart(release, dir, helm)
|
ociChartPath, err := st.getOCIChart(pullChan, release, dir, helm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results <- &chartPrepareResult{err: fmt.Errorf("release %q: %w", release.Name, err)}
|
results <- &chartPrepareResult{err: fmt.Errorf("release %q: %w", release.Name, err)}
|
||||||
|
|
||||||
|
|
@ -2991,7 +3001,7 @@ func (st *HelmState) Reverse() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) getOCIChart(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)
|
repo, name := st.GetRepositoryAndNameFromChartName(release.Chart)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -3008,7 +3018,7 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
||||||
|
|
||||||
qualifiedChartName := fmt.Sprintf("%s/%s:%s", repo.URL, name, chartVersion)
|
qualifiedChartName := fmt.Sprintf("%s/%s:%s", repo.URL, name, chartVersion)
|
||||||
|
|
||||||
err := helm.ChartPull(qualifiedChartName)
|
err := st.pullChart(pullChan, qualifiedChartName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -3039,3 +3049,27 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
||||||
|
|
||||||
return &chartPath, nil
|
return &chartPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a pull command to the pull worker
|
||||||
|
func (st *HelmState) pullChart(pullChan chan *PullCommand, chartRef string) error {
|
||||||
|
response := make(chan error, 1)
|
||||||
|
cmd := &PullCommand{
|
||||||
|
responseChan: response,
|
||||||
|
ChartRef: chartRef,
|
||||||
|
}
|
||||||
|
pullChan <- cmd
|
||||||
|
return <-response
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue