bzp2010 commented on code in PR #2553: URL: https://github.com/apache/apisix-ingress-controller/pull/2553#discussion_r2345870942
########## internal/adc/translator/apisixroute.go: ########## @@ -328,6 +329,26 @@ func (t *Translator) buildService(ar *apiv2.ApisixRoute, rule apiv2.ApisixRouteH return service } +func getPortFromService(svc *v1.Service, backendSvcPort intstr.IntOrString) (int32, error) { + var port int32 + if backendSvcPort.Type == intstr.Int { + port = int32(backendSvcPort.IntValue()) + } else { + found := false + for _, servicePort := range svc.Spec.Ports { + if servicePort.Name == backendSvcPort.StrVal { + port = servicePort.Port Review Comment: The `getPortFromService` directly uses `port` instead of `targetPort`. When using the endpoint as the resolution granularity, this should not be the expected behavior? ########## internal/adc/translator/apisixroute.go: ########## @@ -364,14 +389,26 @@ func (t *Translator) translateApisixRouteStreamBackendResolveGranularity(tctx *p } func (t *Translator) translateApisixRouteBackendResolveGranularityEndpoint(tctx *provider.TranslateContext, arNN types.NamespacedName, backend apiv2.ApisixRouteHTTPBackend) (adc.UpstreamNodes, error) { + serviceNN := types.NamespacedName{ + Namespace: arNN.Namespace, + Name: backend.ServiceName, + } + svc, ok := tctx.Services[serviceNN] + if !ok { + return nil, errors.Errorf("service not found, ApisixRoute: %s, Service: %s", arNN, serviceNN) + } + port, err := getPortFromService(svc, backend.ServicePort) Review Comment: If I understand correctly, when we resolve ports using endpoints as the granularity, resolving the service port alone is insufficient. We must further resolve the targetPort used by the pod through the specified service port, and correctly handle cases where the targetPort is either a string or a number? There is no guarantee that the service port and pod port will use the same value, so directly using the service port is inappropriate. ping @AlinsRan @ronething -- 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: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org