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

Add warnings for the errors encountered on retries #2147

Merged
merged 2 commits into from
Nov 16, 2023
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
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
Loading