allthingssecurity opened a new pull request, #30572: URL: https://github.com/apache/camel/pull/30572
# Description [CAMEL-27315](https://issues.apache.org/jira/browse/CAMEL-27315) This follows [CAMEL-27296](https://issues.apache.org/jira/browse/CAMEL-27296) (a stopped cluster view gives up the leadership and the lease, #30527, merged), which changed the same class. The change here is one statement in `KubernetesLeadershipController.refreshStatusNotLeader`, which CAMEL-27296 did not touch. When the leader pod is no longer ready (it is not in the list of ready pods any more, but still runs), it gives up the leadership: `refreshStatusLeader` moves to NOT_LEADER and tells the notifier that there is no leader. Its next NOT_LEADER run then reads the lease, which still names the pod: - the holder is not a valid leader (it is not ready), so the pod tries to take the lease, which fails because the pod itself is not ready; - the run then ends by publishing the holder of the lease as the leader, for the lease duration. The holder is the pod itself, so the pod reports itself as leader again. The pod announces leader, no leader, leader again (the clustered routes are stopped and started again), and goes on announcing itself on every poll for as long as it is not ready and the lease names it, without the wait in BECOMING_LEADER that a ready holder goes through. Its claim lasts the lease duration after its last read, not the renew deadline. If another pod that is ready takes the lease while this pod reads the list of pods, and this pod then loses its connection to the API server, both pods report themselves as leader for a short time (about the duration of that request). The fix: from NOT_LEADER the pod does not publish itself as the leader. It can only find itself as the holder there when it is not a valid leader (a valid holder moves to BECOMING_LEADER before that statement), so it publishes "no leader" instead. Another holder is published to the listeners as before. Found with a TLA+ model of the lease leader election (two pods, readiness changes, partitions from the API server, crashes, `setDisabled`, the notifier and its expiry). On main it finds a pod in NOT_LEADER that reports itself as leader, a report that lasts longer than the renew deadline after the last read, and two pods that report themselves as leader at the same time. With the change none of these happens (69,786,140 distinct states with one crash, readiness change, partition and `setDisabled` change each; TLC and everystate agree on a smaller scope). Tests: new `KubernetesNotReadyLeaseHolderTest` (the module's `LockTestServer`, both lease resource types): - no pod is ready: the leader gives up the leadership, and must not report it again (checked for twice the lease duration), while the lease still names it; - only the leader is not ready: the other pod takes the lease over and becomes the leader, and the old leader must not report itself as leader after it gave up the leadership; - the pods are ready again: the pod named by the lease leads again (control, passes without the change). On main the first two fail for both resource types (the leader reports itself again a retry period after it gave up the leadership: `[null, mypod1, ...]`). With the change the 6 pass, and the camel-kubernetes cluster tests pass (50 run, 0 failures: `KubernetesClusterServiceTest` 21, `KubernetesClusterViewStopTest` 18, `KubernetesNotReadyLeaseHolderTest` 6, `TimedLeaderNotifierTest` 5). The new class 20 times in one JVM: 120 run, 0 failures. Not changed: a pod that is not the holder still publishes the holder of the lease as the leader, also when that holder is not ready (until another pod takes the lease). This only informs the listeners of that pod. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27315](https://issues.apache.org/jira/browse/CAMEL-27315). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
