allthingssecurity opened a new pull request, #30695: URL: https://github.com/apache/camel/pull/30695
# Description [CAMEL-27353](https://issues.apache.org/jira/browse/CAMEL-27353) `KubernetesClusterView.doStart` takes its client from `KubernetesHelper.getKubernetesClient(configuration)`: the client set with `KubernetesConfiguration.setKubernetesClient`, or else one it creates from the master URL. `doStop` always closed that client. A client set on the configuration belongs to the user, and `KubernetesClusterService.createView` copies the configuration (with the client reference) for each view, so all the views (groups) of the service share it. When one view stopped (its last clustered route removed, its `MasterConsumer` stopped, or `stopView` through JMX), it closed the client of all the others: - the other groups of the pod could no longer read or renew their lease (`IllegalStateException: Client is closed`), lost the leadership locally once the renew deadline had passed, and could not take it again. The lease still named the pod and the pod was ready, so no other pod led these groups either, until the pod became unready; - a view used again (the clustered route added again) started on the closed client and never led again; - any other use of the client by the user failed. This came up in the review of [CAMEL-27296](https://issues.apache.org/jira/browse/CAMEL-27296) (#30527, point 4). It is also why the restart test of that PR passed without its `setRefuseRequests(true)`, and why its three-group tests use a client per view. The change: the view remembers in `doStart` whether it created its client (no client on the configuration) and closes only that one in `doStop`, as `AbstractKubernetesEndpoint.doStop` already does for the endpoints. A view still creates a new client on each start when none is set, so nothing changes for that case. I checked the rest of camel-kubernetes for the same pattern: the endpoints (`AbstractKubernetesEndpoint`, used by all the consumers and producers) close only a client they created; the config map and secret reload tasks close the client of the properties function only when it was not autowired; `KubernetesLeadershipController` and `KubernetesClusterService` do not close a client. So the view was the only place. ([CAMEL-21770](https://issues.apache.org/jira/browse/CAMEL-21770) made the same change for an autowired client of the endpoints and the reload tasks.) Found with a TLA+ model of the views of a cluster service and their clients (start, stop, restart, a refresh of the lease on the client of the view). On main, with a client set on the configuration, the client of the user is closed after the first stop, and a view that is started again runs on a closed client; with clients created by the views it holds on main too. With the change all of these hold for both kinds of client (TLC and everystate agree: 25 distinct states with 2 views and 2 starts each, 49 with 3 starts). Tests: new `KubernetesClusterViewSuppliedClientTest` (the module's `LockTestServer` mock, both lease resource types), one pod that leads two groups with a client set on the configuration of its cluster service: - the view of one group is stopped: the other group must keep its leadership and renew its lease for twice the lease duration, and the client must still work; - the stopped view is used again: it must lead its group again. On main all 4 fail (the other group loses its leadership; the restarted view never leads). With the change they pass. The module tests pass: 251 run, 0 failures, 6 skipped (`KubernetesClusterServiceTest` 21, `KubernetesClusterViewStopTest` 18, `KubernetesClusterViewSuppliedClientTest` 4 among them). `KubernetesClusterViewSuppliedClientTest` 20 times in one JVM: 80 run, 0 failures. After the `LockTestServer` change below, the cluster tests (`org/apache/camel/component/kubernetes/cluster/**`) pass again: 48 run, 0 failures. I also updated a comment of `KubernetesClusterViewStopTest` that described the old behaviour. As a view no longer closes a client set on the configuration, the clients that `KubernetesClusterServiceTest`, `KubernetesClusterViewStopTest` and the new test set there would now stay open after each test (each fabric8 8.0 client with the Vert.x 5 HTTP client has a Vert.x instance of its own), so `LockTestServer` now closes the clients it created when it is destroyed. No upgrade guide entry: a client set on the configuration is now left open for its owner, who closes it, as for the endpoints. # 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-27353](https://issues.apache.org/jira/browse/CAMEL-27353). # 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 `components/camel-kubernetes`, including the formatter and import-sort plugins. No option or generated file changes. 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]
