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

chore(controller): make backoff configurable for tests #3074

Merged
merged 1 commit into from
Dec 5, 2024
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
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 @@
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,
},

Check warning on line 92 in internal/controller/stages/regular_stages.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/stages/regular_stages.go#L86-L92

Added lines #L86 - L92 were not covered by tests
}
}

Expand Down Expand Up @@ -1312,13 +1321,7 @@
// 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
Loading