Skip to content

Commit

Permalink
Add warnings for the errors encountered on retries (#2147)
Browse files Browse the repository at this point in the history
## Description

This adds better messaging when a retry occurs letting users better
rectify flakes.

## Related Issue

Fixes #N/A

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Other (security config, docs update, etc)

## Checklist before merging

- [X] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Racer159 committed Nov 16, 2023
1 parent 89d6f90 commit 356a4da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/internal/packager/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (i *ImageConfig) PushToZarfRegistry() error {
httpTransport := http.DefaultTransport.(*http.Transport).Clone()
httpTransport.TLSClientConfig.InsecureSkipVerify = i.Insecure
progressBar := message.NewProgressBar(totalSize, fmt.Sprintf("Pushing %d images to the zarf registry", len(i.ImageList)))
defer progressBar.Stop()
craneTransport := utils.NewTransport(httpTransport, progressBar)

pushOptions := config.GetCraneOptions(i.Insecure, i.Architectures...)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (p *Packager) Create() (err error) {
return err
}

if err := helpers.Retry(doPull, 3, 5*time.Second); err != nil {
if err := helpers.Retry(doPull, 3, 5*time.Second, message.Warnf); err != nil {
return fmt.Errorf("unable to pull images after 3 attempts: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (p *Packager) pushImagesToRegistry(componentImages []string, noImgChecksum

return helpers.Retry(func() error {
return imgConfig.PushToZarfRegistry()
}, 3, 5*time.Second)
}, 3, 5*time.Second, message.Warnf)
}

// Push all of the components git repos to the configured git server.
Expand Down Expand Up @@ -497,7 +497,7 @@ func (p *Packager) pushReposToRepository(reposPath string, repos []string) error
}

// Try repo push up to 3 times
if err := helpers.Retry(tryPush, 3, 5*time.Second); err != nil {
if err := helpers.Retry(tryPush, 3, 5*time.Second, message.Warnf); err != nil {
return fmt.Errorf("unable to push repo %s to the Git Server: %w", repoURL, err)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/pkg/utils/helpers/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
)

// Retry will retry a function until it succeeds or the timeout is reached, timeout == retries * delay.
func Retry(fn func() error, retries int, delay time.Duration) (err error) {
func Retry(fn func() error, retries int, delay time.Duration, logger func(format string, args ...any)) (err error) {
for r := 0; r < retries; r++ {
err = fn()
if err == nil {
break
}

logger("Encountered an error, retrying (%d/%d): %s", r+1, retries, err.Error())

time.Sleep(delay)
}

Expand Down

0 comments on commit 356a4da

Please sign in to comment.