Skip to content

Commit 4df02a1

Browse files
fix(v3): remove cap and used fixed polling interval (#3094)
* remove cap and used fixed polling interval * bump timeout to 90m
1 parent 1aaaf3b commit 4df02a1

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

pkg-new/upgrade/upgrade.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,8 @@ func createAutopilotPlan(ctx context.Context, cli client.Client, rc runtimeconfi
367367

368368
func waitForAutopilotPlan(ctx context.Context, cli client.Client, logger logrus.FieldLogger) (apv1b2.Plan, error) {
369369
backoff := wait.Backoff{
370-
Duration: time.Second,
371-
Factor: 2.0,
372-
Steps: 75, // ~25 minutes with exponential backoff (1s, 2s, 4s, 8s, 16s, then 20s capped)
373-
Cap: 20 * time.Second,
370+
Duration: 20 * time.Second, // 20-second polling interval
371+
Steps: 90, // 90 attempts × 20s = 1800s = 30 minutes
374372
}
375373

376374
var plan apv1b2.Plan

pkg-new/upgrade/upgrade_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,39 @@ func TestWaitForAutopilotPlan_WaitsForCompletion(t *testing.T) {
480480
assert.Equal(t, core.PlanCompleted, result.Status.State)
481481
}
482482

483+
func TestWaitForAutopilotPlan_LongRunningUpgrade(t *testing.T) {
484+
logger := logrus.New()
485+
logger.SetLevel(logrus.ErrorLevel)
486+
487+
scheme := runtime.NewScheme()
488+
require.NoError(t, apv1b2.Install(scheme))
489+
490+
// Simulate a long-running upgrade that takes more than 5 attempts
491+
// This represents a real k0s infrastructure upgrade that takes several minutes
492+
plan := &apv1b2.Plan{
493+
ObjectMeta: metav1.ObjectMeta{
494+
Name: "autopilot",
495+
},
496+
Spec: apv1b2.PlanSpec{
497+
ID: "long-running-upgrade",
498+
},
499+
Status: apv1b2.PlanStatus{
500+
State: core.PlanSchedulable,
501+
},
502+
}
503+
504+
cli := &mockClientWithStateChange{
505+
Client: fake.NewClientBuilder().WithScheme(scheme).WithObjects(plan).Build(),
506+
plan: plan,
507+
callsUntil: 10, // Will complete after 10 calls - exceeds buggy 5-attempt limit
508+
}
509+
510+
result, err := waitForAutopilotPlan(t.Context(), cli, logger)
511+
require.NoError(t, err, "Should not timeout for long-running upgrades")
512+
assert.Equal(t, "autopilot", result.Name)
513+
assert.Equal(t, core.PlanCompleted, result.Status.State)
514+
}
515+
483516
// Mock client that fails N times before succeeding
484517
type mockClientWithRetries struct {
485518
client.Client

0 commit comments

Comments
 (0)