Skip to content

Commit

Permalink
chore(controller): make backoff configurable for tests (#3074)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco authored Dec 5, 2024
1 parent 0b548db commit 404422a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 10 additions & 7 deletions internal/controller/stages/regular_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,22 @@ type RegularStageReconciler struct {
client client.Client
eventRecorder record.EventRecorder
directivesEngine directives.Engine

backoffCfg wait.Backoff
}

// NewRegularStageReconciler creates a new Stages reconciler.
func NewRegularStageReconciler(cfg ReconcilerConfig, engine directives.Engine) *RegularStageReconciler {
return &RegularStageReconciler{
cfg: cfg,
directivesEngine: engine,
backoffCfg: wait.Backoff{
Duration: 1 * time.Second,
Factor: 2,
Steps: 10,
Cap: 2 * time.Minute,
Jitter: 0.1,
},
}
}

Expand Down Expand Up @@ -1312,13 +1321,7 @@ func (r *RegularStageReconciler) getVerificationResult(
// the symptoms for now. We should investigate the root cause of this
// issue and remove this retry logic when the root cause has been resolved.
ar := rolloutsapi.AnalysisRun{}
if err := retry.OnError(wait.Backoff{
Duration: 1 * time.Second,
Factor: 2,
Steps: 10,
Cap: 2 * time.Minute,
Jitter: 0.1,
}, func(err error) bool {
if err := retry.OnError(r.backoffCfg, func(err error) bool {
return apierrors.IsNotFound(err)
}, func() error {
return r.client.Get(ctx, types.NamespacedName{
Expand Down
15 changes: 15 additions & 0 deletions internal/controller/stages/regular_stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -2273,6 +2274,13 @@ func TestRegularStageReconciler_verifyStageFreight(t *testing.T) {
RolloutsIntegrationEnabled: !tt.rolloutsDisabled,
},
eventRecorder: recorder,
backoffCfg: wait.Backoff{
Duration: 1 * time.Second,
Factor: 2,
Steps: 2,
Cap: 2 * time.Second,
Jitter: 0.1,
},
}

status, err := r.verifyStageFreight(context.Background(), tt.stage, startTime, fixedEndTime)
Expand Down Expand Up @@ -3519,6 +3527,13 @@ func TestRegularStageReconciler_getVerificationResult(t *testing.T) {
cfg: ReconcilerConfig{
RolloutsIntegrationEnabled: !tt.rolloutsDisabled,
},
backoffCfg: wait.Backoff{
Duration: 1 * time.Second,
Factor: 2,
Steps: 2,
Cap: 1 * time.Second,
Jitter: 0.1,
},
}

vi, err := r.getVerificationResult(context.Background(), tt.freight)
Expand Down

0 comments on commit 404422a

Please sign in to comment.