Skip to content

Commit

Permalink
feat: added retry on files sync error (GoogleContainerTools#9261)
Browse files Browse the repository at this point in the history
* feat: added retry on files sync error

* reverted code style changes

* fix(dev.go): change package order

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>

---------

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
  • Loading branch information
idsulik committed Jul 19, 2024
1 parent eb4b07d commit f03f3cf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pkg/skaffold/runner/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strconv"
"time"

"github.com/cenkalti/backoff/v4"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/event"
eventV2 "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/event/v2"
Expand Down Expand Up @@ -85,9 +87,13 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
r.changeSet.ResetSync()
r.intents.ResetSync()
}()

// todo: make this configurable
opts := backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 3)
instrumentation.AddDevIteration("sync")
meterUpdated = true
for _, s := range r.changeSet.NeedsResync() {

syncHandler := func(s *sync.Item) error {
fileCount := len(s.Copy) + len(s.Delete)
output.Default.Fprintf(out, "Syncing %d files for %s\n", fileCount, s.Image)
fileSyncInProgress(fileCount, s.Image)
Expand All @@ -99,10 +105,23 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
eventV2.TaskFailed(constants.DevLoop, err)
endTrace(instrumentation.TraceEndError(err))

return nil
return err
}

fileSyncSucceeded(fileCount, s.Image)

return nil
}
for _, s := range r.changeSet.NeedsResync() {
err := backoff.Retry(
func() error {
return syncHandler(s)
}, backoff.WithContext(opts, childCtx),
)

if err != nil {
return nil
}
}
endTrace()
}
Expand Down

0 comments on commit f03f3cf

Please sign in to comment.