@@ -4,8 +4,11 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "sync"
7
8
"time"
8
9
10
+ "golang.org/x/sync/errgroup"
11
+
9
12
log "github.com/sirupsen/logrus"
10
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
14
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -279,17 +282,32 @@ func (h *Hydrator) hydrate(logCtx *log.Entry, apps []*appv1.Application, project
279
282
syncBranch := apps [0 ].Spec .SourceHydrator .SyncSource .TargetBranch
280
283
targetBranch := apps [0 ].Spec .GetHydrateToSource ().TargetRevision
281
284
282
- var paths []* commitclient.PathDetails
283
- var targetRevision string
284
- var err error
285
- // TODO: parallelize this loop
286
- for _ , app := range apps {
287
- var pathDetails * commitclient.PathDetails
288
- targetRevision , pathDetails , err = h .getManifests (context .Background (), app , targetRevision , projects [app .Spec .Project ])
289
- if err != nil {
290
- return "" , "" , fmt .Errorf ("failed to get manifests for app %q: %w" , app .QualifiedName (), err )
291
- }
292
- paths = append (paths , pathDetails )
285
+ // Get a static SHA revision from the first app so that all apps are hydrated from the same revision.
286
+ targetRevision , pathDetails , err := h .getManifests (context .Background (), apps [0 ], "" , projects [apps [0 ].Spec .Project ])
287
+ if err != nil {
288
+ return "" , "" , fmt .Errorf ("failed to get manifests for app %q: %w" , apps [0 ].QualifiedName (), err )
289
+ }
290
+ paths := []* commitclient.PathDetails {pathDetails }
291
+
292
+ eg , ctx := errgroup .WithContext (context .Background ())
293
+ var mu sync.Mutex
294
+
295
+ for _ , app := range apps [1 :] {
296
+ app := app
297
+ eg .Go (func () error {
298
+ _ , pathDetails , err = h .getManifests (ctx , app , targetRevision , projects [app .Spec .Project ])
299
+ if err != nil {
300
+ return fmt .Errorf ("failed to get manifests for app %q: %w" , app .QualifiedName (), err )
301
+ }
302
+ mu .Lock ()
303
+ paths = append (paths , pathDetails )
304
+ mu .Unlock ()
305
+ return nil
306
+ })
307
+ }
308
+ err = eg .Wait ()
309
+ if err != nil {
310
+ return "" , "" , fmt .Errorf ("failed to get manifests for apps: %w" , err )
293
311
}
294
312
295
313
// If all the apps are under the same project, use that project. Otherwise, use an empty string to indicate that we
0 commit comments