@@ -3,19 +3,34 @@ package translator
33import (
44 "github.com/api7/api7-ingress-controller/api/adc"
55 "github.com/api7/api7-ingress-controller/api/v1alpha1"
6+ "github.com/api7/gopkg/pkg/log"
7+ "go.uber.org/zap"
68 "k8s.io/apimachinery/pkg/types"
9+ gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
710
811 adctypes "github.com/api7/api7-ingress-controller/api/adc"
912)
1013
11- func (t * Translator ) AttachBackendTrafficPolicyToUpstream (policies map [types.NamespacedName ]* v1alpha1.BackendTrafficPolicy , upstream * adctypes.Upstream ) {
14+ func (t * Translator ) AttachBackendTrafficPolicyToUpstream (ref gatewayv1. BackendRef , policies map [types.NamespacedName ]* v1alpha1.BackendTrafficPolicy , upstream * adctypes.Upstream ) {
1215 if len (policies ) == 0 {
1316 return
1417 }
15- for _ , policy := range policies {
16- t .attachBackendTrafficPolicyToUpstream (policy , upstream )
18+ var policy * v1alpha1.BackendTrafficPolicy
19+ for _ , po := range policies {
20+ for _ , targetRef := range po .Spec .TargetRefs {
21+ if ref .Name == targetRef .Name &&
22+ (ref .Namespace != nil && string (* ref .Namespace ) == po .Namespace ) {
23+ policy = po
24+ break
25+ }
26+ }
1727 }
18-
28+ if policy == nil {
29+ return
30+ }
31+ log .Errorw ("attach backend traffic policy to upstream" ,
32+ zap .String ("policy" , policy .Name ))
33+ t .attachBackendTrafficPolicyToUpstream (policy , upstream )
1934}
2035
2136func (t * Translator ) attachBackendTrafficPolicyToUpstream (policy * v1alpha1.BackendTrafficPolicy , upstream * adctypes.Upstream ) {
@@ -29,27 +44,10 @@ func (t *Translator) attachBackendTrafficPolicyToUpstream(policy *v1alpha1.Backe
2944 * upstream .Retries = int64 (* policy .Spec .Retries )
3045 }
3146 if policy .Spec .Timeout != nil {
32- var (
33- connect * int64
34- read * int64
35- send * int64
36- )
37- if policy .Spec .Timeout .Connect .Duration > 0 {
38- connect = new (int64 )
39- * connect = policy .Spec .Timeout .Connect .Duration .Milliseconds ()
40- }
41- if policy .Spec .Timeout .Read .Duration > 0 {
42- read = new (int64 )
43- * read = policy .Spec .Timeout .Read .Duration .Milliseconds ()
44- }
45- if policy .Spec .Timeout .Send .Duration > 0 {
46- send = new (int64 )
47- * send = policy .Spec .Timeout .Send .Duration .Milliseconds ()
48- }
4947 upstream .Timeout = & adctypes.Timeout {
50- Connect : connect ,
51- Read : read ,
52- Send : send ,
48+ Connect : policy . Spec . Timeout . Connect . Duration . Milliseconds () ,
49+ Read : policy . Spec . Timeout . Read . Duration . Milliseconds () ,
50+ Send : policy . Spec . Timeout . Send . Duration . Milliseconds () ,
5351 }
5452 }
5553 if policy .Spec .LoadBalancer != nil {
0 commit comments