Skip to content

Commit 356a4da

Browse files
authored
Add warnings for the errors encountered on retries (#2147)
## 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
1 parent 89d6f90 commit 356a4da

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/internal/packager/images/push.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (i *ImageConfig) PushToZarfRegistry() error {
5151
httpTransport := http.DefaultTransport.(*http.Transport).Clone()
5252
httpTransport.TLSClientConfig.InsecureSkipVerify = i.Insecure
5353
progressBar := message.NewProgressBar(totalSize, fmt.Sprintf("Pushing %d images to the zarf registry", len(i.ImageList)))
54+
defer progressBar.Stop()
5455
craneTransport := utils.NewTransport(httpTransport, progressBar)
5556

5657
pushOptions := config.GetCraneOptions(i.Insecure, i.Architectures...)

src/pkg/packager/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (p *Packager) Create() (err error) {
173173
return err
174174
}
175175

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

src/pkg/packager/deploy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (p *Packager) pushImagesToRegistry(componentImages []string, noImgChecksum
460460

461461
return helpers.Retry(func() error {
462462
return imgConfig.PushToZarfRegistry()
463-
}, 3, 5*time.Second)
463+
}, 3, 5*time.Second, message.Warnf)
464464
}
465465

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

499499
// Try repo push up to 3 times
500-
if err := helpers.Retry(tryPush, 3, 5*time.Second); err != nil {
500+
if err := helpers.Retry(tryPush, 3, 5*time.Second, message.Warnf); err != nil {
501501
return fmt.Errorf("unable to push repo %s to the Git Server: %w", repoURL, err)
502502
}
503503
}

src/pkg/utils/helpers/misc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
)
1313

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

22+
logger("Encountered an error, retrying (%d/%d): %s", r+1, retries, err.Error())
23+
2224
time.Sleep(delay)
2325
}
2426

0 commit comments

Comments
 (0)