Skip to content

Commit a0f5f91

Browse files
committed
refactor: simplify image synchronization logic
1 parent ca3f9bf commit a0f5f91

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

internal/sync/images.go

+16-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/rs/zerolog/log"
1717
"go.opentelemetry.io/otel/attribute"
1818
"go.opentelemetry.io/otel/metric"
19-
"golang.org/x/sync/errgroup"
2019
)
2120

2221
func checkRateLimit(err error) error {
@@ -99,7 +98,7 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
9998

10099
pullAuth, pullAuthName := getAuth(image.GetSourceRegistry(), image.GetSourceRepository())
101100

102-
puller, err := remote.NewPuller(pullAuth)
101+
srcPuller, err := remote.NewPuller(pullAuth)
103102
if err != nil {
104103
return err
105104
}
@@ -109,7 +108,7 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
109108
return err
110109
}
111110

112-
srcLister, err := puller.Lister(ctx, srcRepo)
111+
srcLister, err := srcPuller.Lister(ctx, srcRepo)
113112
if err != nil {
114113
return err
115114
}
@@ -185,9 +184,6 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
185184

186185
// Sync tags
187186
for _, tag := range srcTags {
188-
g, ctx := errgroup.WithContext(ctx)
189-
g.SetLimit(config.SyncMaxErrors.Int())
190-
191187
log.Info().
192188
Str("image", image.Source).
193189
Str("tag", tag).
@@ -197,29 +193,27 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
197193
if err := func() error {
198194
tag := tag
199195

200-
desc, err := pull(ctx, puller, image, tag)
196+
desc, err := pull(ctx, srcPuller, image, tag)
201197
if err != nil {
202198
return err
203199
}
204200

205201
for _, dst := range image.Targets {
206-
g.Go(func() error {
207-
if slices.Contains(dstTags, fmt.Sprintf("%s:%s", dst, tag)) {
208-
log.Info().
209-
Str("image", image.Source).
210-
Str("tag", tag).
211-
Str("target", dst).
212-
Msg("Tag already exists, skipping")
213-
return nil
214-
}
215-
if err := push(ctx, image, desc, dst, tag); err != nil {
216-
log.Error().Err(err).Msg("Failed to push tag")
217-
}
218-
return err
219-
})
202+
if slices.Contains(dstTags, fmt.Sprintf("%s:%s", dst, tag)) {
203+
log.Info().
204+
Str("image", image.Source).
205+
Str("tag", tag).
206+
Str("target", dst).
207+
Msg("Tag already exists, skipping")
208+
return nil
209+
}
210+
if err := push(ctx, image, desc, dst, tag); err != nil {
211+
log.Error().Err(err).Msg("Failed to push tag")
212+
}
213+
return err
220214
}
221215

222-
return g.Wait()
216+
return nil
223217
}(); err != nil {
224218
log.Error().
225219
Err(err).

0 commit comments

Comments
 (0)