konlue opened a new pull request, #7917:
URL: https://github.com/apache/shenyu/pull/7917

   Fixes #7912.
   
   ## Summary
   
   `apiClient` is guarded by 
`@ConditionalOnMissingBean(DeploymentProperties.class)`, but 
`KubernetesConfiguration` itself enables that properties class — so the 
condition can never pass and the `AppsV1Api` bean is never created, no matter 
what the user configures. The `kubernetesScaler` `@Bean` method (conditioned on 
the same properties) is likewise dead code; the working `KubernetesScaler` 
comes from component scanning and is built with a null client, so the first 
scale call NPEs (`scaleByNum` only catches `ApiException`).
   
   ## Modifications
   
   - `apiClient` now backs off on `@ConditionalOnMissingBean(AppsV1Api.class)` 
— a user-supplied client wins; a pre-registered `DeploymentProperties` bean no 
longer suppresses client creation. The `shenyu.k8s.scale.enabled` gate is 
unchanged.
   - Remove the never-effective `kubernetesScaler` `@Bean` method. The 
component-scanned scaler keeps wiring `Optional<AppsV1Api>`; re-registering it 
from configuration would have raced component scan, and a scaler-override path 
never existed before.
   - `scaleByNum` / `scaleByAction` log a warning and no-op when the client is 
absent (scaling disabled via `shenyu.k8s.scale.enabled`, or client creation 
failed): a null client must not NPE the scheduler thread or the startup 
`ScaleTaskInitializer` path. `apiClient` still returns null instead of throwing 
when the cluster is unreachable so that Admin keeps starting without 
Kubernetes; combined with the guard this is now an explicit, logged degradation.
   
   ## Verifying this change
   
   - [x] `KubernetesConfigurationTest` (`ApplicationContextRunner`, first in 
this module): enabled + standard binding creates `apiClient`; a pre-registered 
`DeploymentProperties` bean no longer suppresses it (fails on the previous code 
— zero `AppsV1Api` beans, the issue's repro); a custom `AppsV1Api` wins the 
back-off; disabled creates no client.
   - [x] `KubernetesScalerTest`: with `Optional.empty()` both scale entry 
points are safe no-ops (fails on the previous code with the issue's NPE).
   - [x] Regression tests and Checkstyle pass:
   
     ```bash
     # ScaleServiceTest 11/11 green, TaskSchedulerManagerTest 3/3 green
     ./mvnw -B -ntp -pl shenyu-admin checkstyle:check
     ```
     clean.


-- 
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]

Reply via email to