Make proper use of errgroup context
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
bc890874e1
commit
8d0b54e431
|
@ -589,7 +589,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
|
|||
Chart: helmChart,
|
||||
Dependencies: dwr,
|
||||
}
|
||||
err = dm.Build()
|
||||
err = dm.Build(ctx)
|
||||
if err != nil {
|
||||
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
|
||||
}
|
||||
|
|
|
@ -46,16 +46,20 @@ type DependencyManager struct {
|
|||
}
|
||||
|
||||
// Build compiles and builds the chart dependencies
|
||||
func (dm *DependencyManager) Build() error {
|
||||
func (dm *DependencyManager) Build(ctx context.Context) error {
|
||||
if len(dm.Dependencies) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
errs, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
for _, item := range dm.Dependencies {
|
||||
errs.Go(func() error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
var (
|
||||
ch *helmchart.Chart
|
||||
err error
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package helm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
@ -43,7 +44,7 @@ func TestBuild_WithEmptyDependencies(t *testing.T) {
|
|||
dm := DependencyManager{
|
||||
Dependencies: nil,
|
||||
}
|
||||
if err := dm.Build(); err != nil {
|
||||
if err := dm.Build(context.TODO()); err != nil {
|
||||
t.Errorf("Build() should return nil")
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +120,7 @@ func TestBuild_WithLocalChart(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := dm.Build()
|
||||
err := dm.Build(context.TODO())
|
||||
deps := dm.Chart.Dependencies()
|
||||
|
||||
if (err != nil) && tt.wantErr {
|
||||
|
@ -172,7 +173,7 @@ func TestBuild_WithRemoteChart(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
if err := dm.Build(); err != nil {
|
||||
if err := dm.Build(context.TODO()); err != nil {
|
||||
t.Errorf("Build() expected to not return error: %s", err)
|
||||
}
|
||||
|
||||
|
@ -189,7 +190,7 @@ func TestBuild_WithRemoteChart(t *testing.T) {
|
|||
|
||||
// When repo is not set
|
||||
dm.Dependencies[0].Repo = nil
|
||||
if err := dm.Build(); err == nil {
|
||||
if err := dm.Build(context.TODO()); err == nil {
|
||||
t.Errorf("Build() expected to return error")
|
||||
} else if !strings.Contains(err.Error(), "chartrepo should not be nil") {
|
||||
t.Errorf("Build() expected to return different error, got: %s", err)
|
||||
|
|
Loading…
Reference in New Issue