Skip to content

Commit ab1927d

Browse files
committed
fix test
1 parent c9d5183 commit ab1927d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

internal/adc/translator/apisixroute.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
235235
log.Debugw("failed to retrieve ApisixUpstream from tctx", zap.Any("ApisixUpstream", upsNN))
236236
continue
237237
}
238-
upstream, err := t.translateApisixUpstream(tctx, au, 0)
238+
upstream, err := t.translateApisixUpstream(tctx, au)
239239
if err != nil {
240240
t.Log.Error(err, "failed to translate ApisixUpstream", "ApisixUpstream", utils.NamespacedName(au))
241241
continue
@@ -347,7 +347,7 @@ func (t *Translator) translateApisixRouteHTTPBackend(tctx *provider.TranslateCon
347347
if err != nil {
348348
return nil, err
349349
}
350-
upstream, err = t.translateApisixUpstream(tctx, au, port)
350+
upstream, err = t.translateApisixUpstreamForPort(tctx, au, ptr.To(port))
351351
if err != nil {
352352
return nil, err
353353
}
@@ -356,12 +356,12 @@ func (t *Translator) translateApisixRouteHTTPBackend(tctx *provider.TranslateCon
356356
if backend.ResolveGranularity == apiv2.ResolveGranularityService {
357357
upstream.Nodes, err = t.translateApisixRouteBackendResolveGranularityService(tctx, auNN, backend)
358358
if err != nil {
359-
t.Log.Error(err, "failed to translate backend resolve granularity service", "backend", backend)
359+
return nil, err
360360
}
361361
} else {
362362
upstream.Nodes, err = t.translateApisixRouteBackendResolveGranularityEndpoint(tctx, auNN, backend)
363363
if err != nil {
364-
t.Log.Error(err, "failed to translate backend resolve granularity endpoint", "backend", backend)
364+
return nil, err
365365
}
366366
}
367367

@@ -466,7 +466,7 @@ func (t *Translator) translateStreamRule(tctx *provider.TranslateContext, ar *ap
466466
if err != nil {
467467
return nil, err
468468
}
469-
upstream, _ = t.translateApisixUpstream(tctx, au, port)
469+
upstream, _ = t.translateApisixUpstreamForPort(tctx, au, ptr.To(port))
470470
}
471471
nodes, err := t.translateApisixRouteStreamBackendResolveGranularity(tctx, utils.NamespacedName(ar), part.Backend)
472472
if err != nil {

internal/adc/translator/apisixupstream.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ import (
3434
"github.com/apache/apisix-ingress-controller/internal/utils"
3535
)
3636

37-
func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, au *apiv2.ApisixUpstream, port int32) (*adc.Upstream, error) {
38-
log.Debugw("translating ApisixUpstream", zap.Any("apisixupstream", au), zap.Int32("port", port))
37+
func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, au *apiv2.ApisixUpstream) (*adc.Upstream, error) {
38+
return t.translateApisixUpstreamForPort(tctx, au, nil)
39+
}
40+
41+
func (t *Translator) translateApisixUpstreamForPort(tctx *provider.TranslateContext, au *apiv2.ApisixUpstream, port *int32) (*adc.Upstream, error) {
42+
log.Debugw("translating ApisixUpstream", zap.Any("apisixupstream", au), zap.Int32p("port", port))
3943

4044
ups := adc.NewDefaultUpstream()
4145
ups.Name = composeExternalUpstreamName(au)
@@ -48,10 +52,11 @@ func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, au
4852
return nil, err
4953
}
5054

51-
// If portLevelSettings is configured, we need to validate the ports in
52-
if len(au.Spec.PortLevelSettings) > 0 && port != 0 {
55+
// If PortLevelSettings is configured and a specific port is provided,
56+
// apply the ApisixUpstreamConfig for the matching port to the upstream.
57+
if len(au.Spec.PortLevelSettings) > 0 && port != nil {
5358
for _, pls := range au.Spec.PortLevelSettings {
54-
if pls.Port != port {
59+
if pls.Port != *port {
5560
continue
5661
}
5762
if err := translateApisixUpstreamConfig(tctx, &pls.ApisixUpstreamConfig, ups); err != nil {

0 commit comments

Comments
 (0)