allthingssecurity opened a new pull request, #30762: URL: https://github.com/apache/camel/pull/30762
# Description [CAMEL-27318](https://issues.apache.org/jira/browse/CAMEL-27318) `KubernetesLeadershipController.setDisabled` runs one more `refreshStatus` on the executor of the controller when the value changes, so that the change is applied at once. Every run of `refreshStatus` executes or schedules exactly one next run (the next state, or the next poll after the retry period), so that extra run starts a second chain of refreshes, and it never ends. After N changes there are N+1 chains, and the pod reads the lease and the list of pods N+1 times per retry period. `RebalancingCamelClusterService` calls `setDisabled` on the views of its partitions on every rebalance (a pod joins or leaves, a pod becomes ready or not), so the API calls of a pod grow with each rebalance, for as long as the application runs. The fix keeps one chain: each run carries the id of its chain, and the next run it executes or schedules gets the same id. `setDisabled` starts a new chain (a new id) at once, as before, and a run of an older chain ends without a next run. The runs are on the single thread of the executor, so a run of the old chain that is in progress (for example the wait in BECOMING_LEADER or LOSING_LEADERSHIP) ends normally, and its next run is the one that ends the old chain. Found with a TLA+ model of the refresh loop (the queue of the executor, runs that execute their successor, `setDisabled` at any time, also during a run). On main it finds two chains after one change. With the change there is exactly one chain at all times, the loop never stops, and a run of the newest chain is queued after each change (54 distinct states with 3 changes; TLC and everystate agree). Tests: new `KubernetesLeadershipRefreshTest` (the module's `LockTestServer`, both lease resource types): - the time the follower takes for 20 requests to its API server, before and after `setDisabled(true)` and `setDisabled(false)` 5 times: it must not become much shorter (without the change, 20 requests took about 100 ms after the changes instead of about 2100 ms); - a leader whose view is disabled gives up the leadership and the other pod takes it over (control, passes without the change). Without the change the first fails for both types. With the change the 4 pass, and the cluster tests of camel-kubernetes pass (46 run, 0 failures: `KubernetesClusterServiceTest` 21, `KubernetesClusterViewStopTest` 10, `KubernetesNotReadyLeaseHolderTest` 6, `KubernetesLeadershipRefreshTest` 4, `TimedLeaderNotifierTest` 5; on current main the whole module: 231 run, 0 failures, 6 skipped). The new class 20 times in one JVM (before the rebase onto main): 80 run, 0 failures. # 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-27318](https://issues.apache.org/jira/browse/CAMEL-27318). # 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]
