Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add context to pull and data injections #2654

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/fluxcd/pkg/apis/meta v1.3.0
github.com/fluxcd/source-controller/api v1.2.4
github.com/go-git/go-git/v5 v5.11.0
github.com/go-logr/logr v1.4.1
github.com/goccy/go-yaml v1.11.3
github.com/gofrs/flock v0.8.1
github.com/google/go-containerregistry v0.19.0
Expand Down Expand Up @@ -63,8 +62,6 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require github.com/evanphx/json-patch/v5 v5.6.0 // indirect

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
Expand Down Expand Up @@ -225,6 +222,7 @@ require (
github.com/emicklei/proto v1.12.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/facebookincubator/nvdtools v0.1.5 // indirect
github.com/fatih/camelcase v1.0.0 // indirect
Expand All @@ -246,6 +244,7 @@ require (
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.22.0 // indirect
github.com/go-openapi/errors v0.21.0 // indirect
Expand Down
49 changes: 27 additions & 22 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@
return err
}

if err := helpers.Retry(sc, 2, 5*time.Second, message.Warnf); err != nil {
if err := helpers.RetryWithContext(ctx, sc, 2, 5*time.Second, message.Warnf); err != nil {
message.Warnf("Failed to save images in parallel, falling back to sequential save: %s", err.Error())

if err := helpers.Retry(ss, 2, 5*time.Second, message.Warnf); err != nil {
if err := helpers.RetryWithContext(ctx, ss, 2, 5*time.Second, message.Warnf); err != nil {

Check warning on line 246 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L246

Added line #L246 was not covered by tests
return nil, err
}
}
Expand Down Expand Up @@ -348,30 +348,35 @@
for info, img := range m {
info, img := info, img
eg.Go(func() error {
desc, err := partial.Descriptor(img)
if err != nil {
return err
}
select {
case <-ectx.Done():
return ectx.Err()

Check warning on line 353 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L352-L353

Added lines #L352 - L353 were not covered by tests
default:
desc, err := partial.Descriptor(img)
if err != nil {
return err

Check warning on line 357 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L357

Added line #L357 was not covered by tests
}

if err := cl.WriteImage(img); err != nil {
if err := CleanupInProgressLayers(ectx, img); err != nil {
message.WarnErr(err, "failed to clean up in-progress layers, please run `zarf tools clear-cache`")
if err := cl.WriteImage(img); err != nil {
if err := CleanupInProgressLayers(ectx, img); err != nil {
message.WarnErr(err, "failed to clean up in-progress layers, please run `zarf tools clear-cache`")

Check warning on line 362 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L361-L362

Added lines #L361 - L362 were not covered by tests
}
return err

Check warning on line 364 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L364

Added line #L364 was not covered by tests
}
return err
}

mu.Lock()
defer mu.Unlock()
annotations := map[string]string{
ocispec.AnnotationBaseImageName: info.Reference,
}
desc.Annotations = annotations
if err := cl.AppendDescriptor(*desc); err != nil {
return err
}
mu.Lock()
defer mu.Unlock()
annotations := map[string]string{
ocispec.AnnotationBaseImageName: info.Reference,
}
desc.Annotations = annotations
if err := cl.AppendDescriptor(*desc); err != nil {
return err

Check warning on line 374 in src/internal/packager/images/pull.go

View check run for this annotation

Codecov / codecov/patch

src/internal/packager/images/pull.go#L374

Added line #L374 was not covered by tests
}

saved[info] = img
return nil
saved[info] = img
return nil
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
}

// Try repo push up to retry limit
if err := helpers.Retry(tryPush, p.cfg.PkgOpts.Retries, 5*time.Second, message.Warnf); err != nil {
if err := helpers.RetryWithContext(ctx, tryPush, p.cfg.PkgOpts.Retries, 5*time.Second, message.Warnf); err != nil {

Check warning on line 569 in src/pkg/packager/deploy.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/deploy.go#L569

Added line #L569 was not covered by tests
return fmt.Errorf("unable to push repo %s to the Git Server: %w", repoURL, err)
}
}
Expand Down
Loading