Copilot commented on code in PR #2582:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2582#discussion_r2384420337
##########
internal/adc/translator/apisixupstream.go:
##########
@@ -33,50 +34,73 @@ 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) (*adc.Upstream, error) {
+ return t.translateApisixUpstreamForPort(tctx, au, nil)
+}
+
+func (t *Translator) translateApisixUpstreamForPort(tctx
*provider.TranslateContext, au *apiv2.ApisixUpstream, port *int32)
(*adc.Upstream, error) {
+ log.Debugw("translating ApisixUpstream", zap.Any("apisixupstream", au),
zap.Int32p("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 and a specific port is provided,
+ // apply the ApisixUpstreamConfig for the matching port to the upstream.
+ if len(au.Spec.PortLevelSettings) > 0 && port != nil {
+ for _, pls := range au.Spec.PortLevelSettings {
+ if pls.Port != *port {
+ continue
+ }
+ if err := translateApisixUpstreamConfig(tctx,
&pls.ApisixUpstreamConfig, ups); err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ log.Debugw("translated ApisixUpstream", zap.Any("upstream", ups))
+
+ return ups, nil
+}
+
+func translateApisixUpstreamConfig(tctx *provider.TranslateContext, config
*apiv2.ApisixUpstreamConfig, ups *adc.Upstream) (err error) {
+ for _, f := range []func(*apiv2.ApisixUpstreamConfig, *adc.Upstream)
error{
translateApisixUpstreamScheme,
translateApisixUpstreamLoadBalancer,
translateApisixUpstreamRetriesAndTimeout,
translateApisixUpstreamPassHost,
translateUpstreamHealthCheck,
translateUpstreamDiscovery,
} {
- if err = f(au, ups); err != nil {
+ if err = f(config, ups); err != nil {
return
}
}
- for _, f := range []func(*provider.TranslateContext,
*apiv2.ApisixUpstream, *adc.Upstream) error{
+ for _, f := range []func(*provider.TranslateContext,
*apiv2.ApisixUpstreamConfig, *adc.Upstream) error{
translateApisixUpstreamClientTLS,
- translateApisixUpstreamExternalNodes,
} {
- if err = f(tctx, au, ups); err != nil {
+ if err = f(tctx, config, ups); err != nil {
return
}
}
Review Comment:
[nitpick] The function signature change from accepting
`*apiv2.ApisixUpstream` to `*apiv2.ApisixUpstreamConfig` breaks consistency
with other translator functions. Consider maintaining the original pattern or
updating all related functions to use the config pattern consistently.
--
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]