Skip to content

Commit 3795274

Browse files
fix(e2e): wait for leader election & measure timing for better monitoring
TestClusterExtensionAfterOLMUpgrade was failing due to increased leader election timeouts, causing reconciliation checks to run before leadership was acquired. This fix ensures the test explicitly waits for leader election logs (`"successfully acquired lease"`) before verifying reconciliation. Additionally, the test now measures and logs the leader election duration to help monitor election timing.
1 parent c3a4406 commit 3795274

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

catalogd/cmd/catalogd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ func main() {
235235
LeaderElectionID: "catalogd-operator-lock",
236236
// Recommended Leader Election values
237237
// https://github.com/openshift/enhancements/blob/61581dcd985130357d6e4b0e72b87ee35394bf6e/CONVENTIONS.md#handling-kube-apiserver-disruption
238-
LeaseDuration: ptr.To(137 * time.Second),
239-
RenewDeadline: ptr.To(107 * time.Second),
240-
RetryPeriod: ptr.To(26 * time.Second),
238+
LeaseDuration: ptr.To(137 * time.Second), // Default: 15s
239+
RenewDeadline: ptr.To(107 * time.Second), // Default: 10s
240+
RetryPeriod: ptr.To(26 * time.Second), // Default: 2s
241241

242242
WebhookServer: webhookServer,
243243
Cache: cacheOptions,

cmd/operator-controller/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ func main() {
235235
LeaderElectionID: "9c4404e7.operatorframework.io",
236236
// Recommended Leader Election values
237237
// https://github.com/openshift/enhancements/blob/61581dcd985130357d6e4b0e72b87ee35394bf6e/CONVENTIONS.md#handling-kube-apiserver-disruption
238-
LeaseDuration: ptr.To(137 * time.Second),
239-
RenewDeadline: ptr.To(107 * time.Second),
240-
RetryPeriod: ptr.To(26 * time.Second),
238+
LeaseDuration: ptr.To(137 * time.Second), // Default: 15s
239+
RenewDeadline: ptr.To(107 * time.Second), // Default: 10s
240+
RetryPeriod: ptr.To(26 * time.Second), // Default: 2s
241241

242242
Cache: cacheOptions,
243243
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily

test/upgrade-e2e/post_upgrade_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
4242

4343
t.Log("Reading logs to make sure that ClusterExtension was reconciled by operator-controller before we update it")
4444
// Make sure that after we upgrade OLM itself we can still reconcile old objects without any changes
45+
t.Log("Start measuring leader election time")
46+
leaderStartTime := time.Now()
47+
leaderElectionCtx, leaderCancel := context.WithTimeout(ctx, 1*time.Minute)
48+
defer leaderCancel()
49+
50+
leaderSubstrings := []string{"successfully acquired lease"}
51+
leaderElected, err := watchPodLogsForSubstring(leaderElectionCtx, managerPod, "manager", leaderSubstrings...)
52+
require.NoError(t, err)
53+
require.True(t, leaderElected)
54+
leaderElectionDuration := time.Since(leaderStartTime)
55+
t.Logf("Leader election took %v seconds", leaderElectionDuration.Seconds())
56+
57+
t.Log("Check ClusterExtension reconciliation")
4558
logCtx, cancel := context.WithTimeout(ctx, time.Minute)
4659
defer cancel()
4760
substrings := []string{

0 commit comments

Comments
 (0)