wy471x opened a new pull request, #7285: URL: https://github.com/apache/shenyu/pull/7285
Fixes #6491 Make sure that: - [X] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [X] You submit test cases (unit or integration tests) that back your changes. - [X] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. ## Summary `IngressReconciler.reconcile()` read the annotations of the current ingress and of the cached ingress with `getMetadata().getAnnotations()`. For a valid `networking.k8s.io/v1` ingress that selects the controller with `spec.ingressClassName: shenyu` instead of the `kubernetes.io/ingress.class` annotation, `getAnnotations()` returns `null` and reconcile failed with a `NullPointerException`: - before `checkIngressClass()` could accept the ingress, so the ingress was never translated into selectors/rules; - before the delete cleanup branch, so deleting such an ingress never removed the cached selectors, rules and TLS state. ### Changes: 1. `IngressReconciler.getAnnotations(V1Ingress)` (IngressReconciler.java:697) — new null safe accessor, absent `metadata` or `annotations` are treated as an empty map. 2. `IngressReconciler.reconcile()` (IngressReconciler.java:163) — resolves the annotations with the new accessor before enabling plugins, so an annotation free ingress reaches `checkIngressClass()` and is reconciled through `spec.ingressClassName`. 3. `IngressReconciler.doDeleteConfigByIngress()` (IngressReconciler.java:218) — reads the annotations of the cached ingress once through the new accessor; an annotation free ingress now falls through to the divide cleanup instead of throwing, so `deleteSelectorByIngressName()`, the service cache removal and the TLS/domain cleanup all run. 4. `IngressReconciler.getPluginName()` (IngressReconciler.java:704) — resolves the plugin from the null safe annotation map, an ingress without plugin annotations keeps resolving to the divide plugin. 5. `IngressParser.getBooleanAnnotation()` (IngressParser.java:99) — uses `MapUtils.emptyIfNull` so parsing an ingress without annotations no longer fails while reading the plugin enabled annotations. ### Test Cases: `IngressReconcilerMissingAnnotationsTest` (new) — builds an ingress without annotations that selects the controller through `spec.ingressClassName: shenyu`: - `testReconcileIngressWithoutAnnotations` — reconcile does not throw, the divide selector is saved and the service is registered in `ServiceIngressCache`. - `testReconcileDeletedIngressWithoutAnnotations` — after the ingress disappears from the lister, reconcile does not throw and removes the cached ingress, the divide selector ids and the service cache entry, and deletes the selector data. Both tests were verified to fail with the original code (`NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "annotations" is null`) and to pass with the fix. ## Verification - `mvn -pl shenyu-kubernetes-controller test` — 22 tests, 0 failures. - `mvn -pl shenyu-kubernetes-controller validate` — checkstyle passed. close #6491 -- 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]
