Copilot commented on code in PR #2582:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2582#discussion_r2384417702
##########
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:
The comment is incomplete and unclear. It should explain what validation
occurs and complete the sentence properly.
```suggestion
// If PortLevelSettings is configured and a specific port is provided,
// apply the ApisixUpstreamConfig for the matching port to the upstream.
```
##########
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:
Errors are logged but not returned, causing the function to continue with
potentially invalid state. The errors should be returned to the caller.
```suggestion
return nil, err
}
} else {
upstream.Nodes, err =
t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
if err != nil {
return nil, err
```
--
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]