Repository navigation
Conversation
Aias00
left a comment
There was a problem hiding this comment.
Thanks @wy471x!
The null-safety guards are correct and well-placed:
ingress.getMetadata().getLabels()is passed straight intoparseIngressRuleand can benullfor an ingress without labels, so the oldlabels.keySet()was a guaranteed NPE; the null/empty guard fixes that. Skipping the whole path entry (rather than registering anIngressConfigurationwith empty rules/metadata) is the right outcome — a selector with no rules and no service metadata would be meaningless.- Guarding the
serviceListerlookup is equally important: the service may legitimately not be in the informer cache yet during startup/reconcile races, and warn-and-continue lets a later reconcile pick it up instead of crashing the parse loop. - The extra
service.getMetadata()null check closes the remaining dereference chain.
The three test files cover the null-labels, missing-service, and happy-path cases for each parser, and the mocked Lister/Indexer setup matches how the production code queries the cache. LGTM, approving.
|
@wy471x Thanks for the fix. This PR currently has merge conflicts and needs to be rebased/merged with the latest target branch before it can be reviewed and merged. Could you please resolve the conflicts and update the PR? |
Aias00
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES (PMC Aias00): this PR has merge conflicts (CONFLICTING) and cannot be merged. Please rebase onto the latest master and resolve the conflicts, then request a re-review.
# Conflicts: # shenyu-kubernetes-controller/src/test/java/org/apache/shenyu/k8s/parser/DubboIngressParserTest.java
The Dubbo ingress parser only emits an IngressConfiguration (and thus a selector) for a path when the ingress carries metadata labels, so the protocol-parsing tests and the null-label regression tests ended up with an empty route config list. Give those tests a non-empty labels map via a shared metadataLabels() helper. Assertions are unchanged.
Aias00
left a comment
There was a problem hiding this comment.
Approving — consistent null-safety fix across all three parsers.
The chained expression
serviceLister.namespace(namespace).get(labels.get(label)).getMetadata().getAnnotations();has three unguarded links. Any of them being null — an Ingress with no selector labels, a label naming a Service the lister hasn't cached (or that was just deleted), or a Service whose getMetadata() is null — throws an NPE inside the reconcile loop. Since this runs on every Ingress event, a single unresolvable reference can wedge the controller's parsing path.
The fix is applied identically in DubboIngressParser, GrpcParser and SofaParser:
V1Service service = serviceLister.namespace(namespace).get(labels.get(label));
if (Objects.isNull(service) || Objects.isNull(service.getMetadata())) {
LOG.warn("Service {} not found in namespace {}", labels.get(label), namespace);
continue;
}Three things make this the right shape:
- The
labels == null || labels.isEmpty()guard is hoisted above the loop, so an Ingress without selector labels is skipped cleanly rather than entering the iteration at all. continue(not a bareif) means a missing Service skips just that label and the remaining labels still get parsed — a partial failure doesn't discard the whole rule.- The
LOG.warnnames both the Service and the namespace, which is exactly what an operator needs to diagnose a stale selector.
Consistency across the three parsers matters here because they duplicate this logic; fixing only one would leave the same bug latent in the others.
One note for coordination: SofaParser is touched here while #6308 proposes removing sofa support entirely. Whichever lands second will need a rebase — not a problem with this change, just flagging the overlap.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
Bug Fix (3 files)
DubboIngressParser.java, GrpcParser.java, SofaParser.java — in each parseIngressRule method, added null-safety guards before iterating over labels:
warning and continue, allowing a later reconcile to pick it up once the service cache is populated.
Unit Tests (3 new files, 9 tests)
close #6486