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

   Fixes #6492
   
   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
   
   `ContextPathParser` built the context mapping rule from the annotations of 
the ingress object, while the documented gRPC and Sofa setup declares the 
context path on the metadata service, next to the RPC annotations and 
referenced by the `shenyu.apache.org/metadata-labels-*` label of the ingress, 
exactly like `GrpcParser` and `SofaParser` read their metadata. Two defects 
followed from that:
   
   - For a Prefix path whose context path annotation is not on the ingress, the 
parser generated a rule with `contextPath == null` and a `null/**` URI 
condition, i.e. a rule that can never match a valid request.
   - An ingress without any annotation (a shape that is valid through 
`spec.ingressClassName`) failed the parse with a `NullPointerException` while 
building the rule handle.
   
   ### Changes:
   
   1. `ContextPathParser.resolveContextPathAnnotations(V1Ingress)` 
(ContextPathParser.java:153) — resolves 
`shenyu.apache.org/plugin-context-path-path`, `...-add-prefix` and 
`...-add-prefixed` from the ingress and falls back to the annotations of the 
services referenced by the ingress labels. The lookup matches the resource the 
RPC parsers use for their metadata, so the gRPC/Sofa example layout 
(`plugin-context-path-path: /grpc` on the Service) is now the layout the parser 
understands.
   2. `ContextPathParser.getReferencedServiceAnnotations(String, Map)` 
(ContextPathParser.java:170) — reads the candidate annotations from the label 
referenced services, skipping labels that do not name a registered service 
(labels such as `app: foo`) and services without metadata.
   3. `ContextPathParser.resolveContextPathAnnotations(V1Ingress)` — the 
ingress annotation wins over the service annotation when both are present, so 
existing ingress-only configurations (the divide/HTTP case) keep their 
behaviour.
   4. `ContextPathParser.parseIngressRule(...)` (ContextPathParser.java:119) — 
skips a path when no context path annotation can be resolved, instead of 
emitting the broken `contextPath: null` / `null/**` rule.
   
   The skip introduced by #7036 (generic context path parsing is not applied to 
an ingress that enables an RPC plugin) is deliberately left untouched.
   
   ### Test Cases:
   
   `ContextPathParserAnnotationsTest` (new):
   
   - `testParseWithoutContextPathAnnotation` — a Prefix path ingress without 
the annotation produces no route config (previously a rule with a `null/**` 
condition).
   - `testParseContextPathFromMetadataService` — the `plugin-context-path-path: 
/grpc` annotation of the label referenced service yields `contextPath: /grpc`, 
rule name `/grpc` and condition `/grpc/**` (the gRPC/Sofa example layout).
   - `testIngressAnnotationWins` — the ingress annotation is preferred when the 
service declares a different context path.
   - `testParseWithUnknownLabelServices` — labels that are not registered 
services (or whose service has no annotations) are skipped without failing.
   
   Three of the four tests fail with the original code (`NullPointerException: 
... because "annotations" is null`), the fourth guards the existing ingress 
annotation behaviour.
   
   ## Verification
   
   - `mvn -pl shenyu-kubernetes-controller test` — 24 tests, 0 failures.
   - `mvn -pl shenyu-kubernetes-controller validate` — checkstyle passed.
   
   close #6492


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