Copilot commented on code in PR #7057:
URL: https://github.com/apache/shenyu/pull/7057#discussion_r4032746686
##########
shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/DubboIngressParser.java:
##########
@@ -238,8 +238,15 @@ private List<IngressConfiguration> parseIngressRule(final
V1IngressRule ingressR
SelectorData selectorData = createSelectorData(pathPath,
conditionList, upstreamList);
List<RuleData> ruleDataList = new ArrayList<>();
List<MetaData> metaDataList = new ArrayList<>();
+ if (Objects.isNull(labels)) {
+ return res;
+ }
for (String label : labels.keySet()) {
- Map<String, String> metadataAnnotations =
serviceLister.namespace(namespace).get(labels.get(label)).getMetadata().getAnnotations();
+ V1Service service =
serviceLister.namespace(namespace).get(labels.get(label));
+ if (Objects.isNull(service)) {
+ continue;
+ }
+ Map<String, String> metadataAnnotations =
service.getMetadata().getAnnotations();
Review Comment:
`metadata.annotations` is optional on a Kubernetes Service, so this
assignment can produce `null` even when the Service exists. The subsequent
`getRuleConditionList` and `parseMetaData` calls dereference that map and still
throw an NPE; normalize the annotation map (or skip the label) before using it.
##########
shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/SofaParser.java:
##########
@@ -169,8 +169,15 @@ private List<IngressConfiguration> parseIngressRule(final
V1IngressRule ingressR
SelectorData selectorData =
createSelectorData(path.getPath(), conditionList);
List<RuleData> ruleDataList = new ArrayList<>();
List<MetaData> metaDataList = new ArrayList<>();
+ if (Objects.isNull(labels)) {
+ return res;
+ }
for (String label : labels.keySet()) {
- Map<String, String> metadataAnnotations =
serviceLister.namespace(namespace).get(labels.get(label)).getMetadata().getAnnotations();
+ V1Service service =
serviceLister.namespace(namespace).get(labels.get(label));
+ if (Objects.isNull(service)) {
+ continue;
+ }
+ Map<String, String> metadataAnnotations =
service.getMetadata().getAnnotations();
Review Comment:
`metadata.annotations` is optional on a Kubernetes Service, so this
assignment can produce `null` even when the Service exists. The subsequent
`getRuleConditionList` and `parseMetaData` calls dereference that map and still
throw an NPE; normalize the annotation map (or skip the label) before using it.
##########
shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/GrpcParser.java:
##########
@@ -252,8 +252,15 @@ private List<IngressConfiguration> parseIngressRule(final
V1IngressRule ingressR
SelectorData selectorData = createSelectorData(pathPath,
conditionList, grpcUpstreamList);
List<RuleData> ruleDataList = new ArrayList<>();
List<MetaData> metaDataList = new ArrayList<>();
+ if (Objects.isNull(labels)) {
+ return res;
+ }
for (String label : labels.keySet()) {
- Map<String, String> metadataAnnotations =
serviceLister.namespace(namespace).get(labels.get(label)).getMetadata().getAnnotations();
+ V1Service service =
serviceLister.namespace(namespace).get(labels.get(label));
+ if (Objects.isNull(service)) {
+ continue;
+ }
+ Map<String, String> metadataAnnotations =
service.getMetadata().getAnnotations();
Review Comment:
`metadata.annotations` is optional on a Kubernetes Service, so this
assignment can produce `null` even when the Service exists. The subsequent
`getRuleConditionList` and `parseMetaData` calls dereference that map and still
throw an NPE; normalize the annotation map (or skip the label) before using it.
--
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]