Skip to content

Commit

Permalink
use environment variable for workers
Browse files Browse the repository at this point in the history
  • Loading branch information
joejstuart committed Nov 4, 2024
1 parent 8df63cf commit eb0fefa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions internal/applicationsnapshot/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"context"
"errors"
"fmt"
"os"
"runtime/trace"
"sort"
"strconv"

"github.com/google/go-containerregistry/pkg/name"
app "github.com/konflux-ci/application-api/api/v1alpha1"
Expand All @@ -36,7 +38,11 @@ import (
"github.com/enterprise-contract/ec-cli/internal/utils/oci"
)

const unnamed = "Unnamed"
const (
unnamed = "Unnamed"
workersEnvVar = "IMAGE_INDEX_WORKERS"
defaultWorkers = 5
)

type Input struct {
File string // Deprecated: replaced by images
Expand Down Expand Up @@ -246,11 +252,10 @@ func expandImageIndex(ctx context.Context, snap *app.SnapshotSpec) {

client := oci.NewClient(ctx)

workers := 5
componentChan := make(chan []app.SnapshotComponent, len(snap.Components))
errorsChan := make(chan error, len(snap.Components))
g, _ := errgroup.WithContext(ctx)
g.SetLimit(workers)
g.SetLimit(imageWorkers())
for _, component := range snap.Components {
// fetch manifests concurrently
g.Go(func() error {
Expand Down Expand Up @@ -285,3 +290,13 @@ func expandImageIndex(ctx context.Context, snap *app.SnapshotSpec) {
}
log.Debugf("Snap component after expanding the image index is %v", snap.Components)
}

func imageWorkers() int {
workers := defaultWorkers
if value, exists := os.LookupEnv(workersEnvVar); exists {
if parsed, err := strconv.Atoi(value); err == nil {
workers = parsed
}

Check warning on line 299 in internal/applicationsnapshot/input.go

View check run for this annotation

Codecov / codecov/patch

internal/applicationsnapshot/input.go#L297-L299

Added lines #L297 - L299 were not covered by tests
}
return workers
}

0 comments on commit eb0fefa

Please sign in to comment.