AlinsRan commented on code in PR #2582:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2582#discussion_r2384420113


##########
internal/adc/translator/apisixupstream.go:
##########
@@ -33,50 +34,68 @@ import (
        "github.com/apache/apisix-ingress-controller/internal/utils"
 )
 
-func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, 
au *apiv2.ApisixUpstream) (ups *adc.Upstream, err error) {
-       ups = adc.NewDefaultUpstream()
-       for _, f := range []func(*apiv2.ApisixUpstream, *adc.Upstream) error{
-               patchApisixUpstreamBasics,
+func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, 
au *apiv2.ApisixUpstream, port int32) (*adc.Upstream, error) {
+       log.Debugw("translating ApisixUpstream", zap.Any("apisixupstream", au), 
zap.Int32("port", port))
+
+       ups := adc.NewDefaultUpstream()
+       ups.Name = composeExternalUpstreamName(au)
+       maps.Copy(ups.Labels, au.Labels)
+
+       if err := translateApisixUpstreamConfig(tctx, 
&au.Spec.ApisixUpstreamConfig, ups); err != nil {
+               return nil, err
+       }
+       if err := translateApisixUpstreamExternalNodes(tctx, au, ups); err != 
nil {
+               return nil, err
+       }
+
+       // If portLevelSettings is configured, we need to validate the ports in

Review Comment:
   fixed.



##########
internal/adc/translator/apisixroute.go:
##########
@@ -350,6 +332,45 @@ func getPortFromService(svc *v1.Service, backendSvcPort 
intstr.IntOrString) (int
        return port, nil
 }
 
+func (t *Translator) translateApisixRouteHTTPBackend(tctx 
*provider.TranslateContext, ar *apiv2.ApisixRoute, backend 
apiv2.ApisixRouteHTTPBackend) (*adc.Upstream, error) {
+       auNN := types.NamespacedName{
+               Namespace: ar.Namespace,
+               Name:      backend.ServiceName,
+       }
+       upstream := adc.NewDefaultUpstream()
+       if au, ok := tctx.Upstreams[auNN]; ok {
+               svc := tctx.Services[auNN]
+               if svc == nil {
+                       return upstream, nil
+               }
+               port, err := getPortFromService(svc, backend.ServicePort)
+               if err != nil {
+                       return nil, err
+               }
+               upstream, err = t.translateApisixUpstream(tctx, au, port)
+               if err != nil {
+                       return nil, err
+               }
+       }
+       var err error
+       if backend.ResolveGranularity == apiv2.ResolveGranularityService {
+               upstream.Nodes, err = 
t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
+               if err != nil {
+                       t.Log.Error(err, "failed to translate backend resolve 
granularity service", "backend", backend)
+               }
+       } else {
+               upstream.Nodes, err = 
t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
+               if err != nil {
+                       t.Log.Error(err, "failed to translate backend resolve 
granularity endpoint", "backend", backend)

Review Comment:
   fixed.



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