Skip to content

Commit

Permalink
make git-push retry internally on non-fast-forward errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <[email protected]>
  • Loading branch information
krancour committed Dec 12, 2024
1 parent d8a4f1a commit ce3b000
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/directives/git_pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package directives
import (
"context"
"fmt"
"time"

securejoin "github.com/cyphar/filepath-securejoin"
"github.com/xeipuuv/gojsonschema"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
"github.com/akuity/kargo/internal/controller/git"
Expand Down Expand Up @@ -127,7 +130,20 @@ func (g *gitPushPusher) runPromotionStep(
fmt.Errorf("error getting current branch: %w", err)
}
}
if err = workTree.Push(pushOpts); err != nil {

if err = retry.OnError(
wait.Backoff{ // TODO(krancour): Make this at least partially configurable
Duration: 1 * time.Second,
Factor: 2,
Steps: 10,
Cap: 2 * time.Minute,
Jitter: 0.1,
},
git.IsNonFastForward,
func() error {
return workTree.Push(pushOpts)
},
); err != nil {
if git.IsMergeConflict(err) {
// Special case: A merge conflict requires manual resolution and no amount
// of retries will fix that.
Expand All @@ -137,6 +153,7 @@ func (g *gitPushPusher) runPromotionStep(
return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored},
fmt.Errorf("error pushing commits to remote: %w", err)
}

commitID, err := workTree.LastCommitID()
if err != nil {
return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored},
Expand Down

0 comments on commit ce3b000

Please sign in to comment.