Skip to content

Commit f5b474a

Browse files
committed
resolve comments
1 parent 91d18b6 commit f5b474a

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

internal/provider/adc/translator/apisixroute.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ import (
3232

3333
func (t *Translator) TranslateApisixRoute(tctx *provider.TranslateContext, ar *apiv2.ApisixRoute) (result *TranslateResult, err error) {
3434
result = &TranslateResult{}
35-
for ruleIndex, http := range ar.Spec.HTTP {
35+
for ruleIndex, rule := range ar.Spec.HTTP {
3636
var timeout *adc.Timeout
37-
if http.Timeout != nil {
37+
if rule.Timeout != nil {
3838
defaultTimeout := metav1.Duration{Duration: apiv2.DefaultUpstreamTimeout}
3939
timeout = &adc.Timeout{
40-
Connect: cmp.Or(int(http.Timeout.Connect.Seconds()), int(defaultTimeout.Seconds())),
41-
Read: cmp.Or(int(http.Timeout.Connect.Seconds()), int(defaultTimeout.Seconds())),
42-
Send: cmp.Or(int(http.Timeout.Connect.Seconds()), int(defaultTimeout.Seconds())),
40+
Connect: cmp.Or(int(rule.Timeout.Connect.Seconds()), int(defaultTimeout.Seconds())),
41+
Read: cmp.Or(int(rule.Timeout.Read.Seconds()), int(defaultTimeout.Seconds())),
42+
Send: cmp.Or(int(rule.Timeout.Send.Seconds()), int(defaultTimeout.Seconds())),
4343
}
4444
}
4545

4646
var plugins = make(adc.Plugins)
47-
for _, plugin := range http.Plugins {
47+
for _, plugin := range rule.Plugins {
4848
if !plugin.Enable {
4949
continue
5050
}
@@ -66,26 +66,26 @@ func (t *Translator) TranslateApisixRoute(tctx *provider.TranslateContext, ar *a
6666
}
6767

6868
// add Authentication plugins
69-
if http.Authentication.Enable {
70-
switch http.Authentication.Type {
69+
if rule.Authentication.Enable {
70+
switch rule.Authentication.Type {
7171
case "keyAuth":
72-
plugins["key-auth"] = http.Authentication.KeyAuth
72+
plugins["key-auth"] = rule.Authentication.KeyAuth
7373
case "basicAuth":
7474
plugins["basic-auth"] = make(map[string]any)
7575
case "wolfRBAC":
7676
plugins["wolf-rbac"] = make(map[string]any)
7777
case "jwtAuth":
78-
plugins["jwt-auth"] = http.Authentication.JwtAuth
78+
plugins["jwt-auth"] = rule.Authentication.JwtAuth
7979
case "hmacAuth":
8080
plugins["hmac-auth"] = make(map[string]any)
8181
case "ldapAuth":
82-
plugins["ldap-auth"] = http.Authentication.LDAPAuth
82+
plugins["ldap-auth"] = rule.Authentication.LDAPAuth
8383
default:
8484
plugins["basic-auth"] = make(map[string]any)
8585
}
8686
}
8787

88-
vars, err := http.Match.NginxVars.ToVars()
88+
vars, err := rule.Match.NginxVars.ToVars()
8989
if err != nil {
9090
return nil, err
9191
}
@@ -97,24 +97,24 @@ func (t *Translator) TranslateApisixRoute(tctx *provider.TranslateContext, ar *a
9797
labels = label.GenLabel(ar)
9898
)
9999
// translate to adc.Route
100-
route.Name = adc.ComposeRouteName(ar.Namespace, ar.Name, http.Name)
100+
route.Name = adc.ComposeRouteName(ar.Namespace, ar.Name, rule.Name)
101101
route.ID = id.GenID(route.Name)
102102
route.Desc = "Created by apisix-ingress-controller, DO NOT modify it manually"
103103
route.Labels = labels
104104
route.EnableWebsocket = ptr.To(true)
105-
route.FilterFunc = http.Match.FilterFunc
106-
route.Hosts = http.Match.Hosts
107-
route.Methods = http.Match.Methods
105+
route.FilterFunc = rule.Match.FilterFunc
106+
route.Hosts = rule.Match.Hosts
107+
route.Methods = rule.Match.Methods
108108
route.Plugins = plugins
109-
route.Priority = ptr.To(int64(http.Priority))
110-
route.RemoteAddrs = http.Match.RemoteAddrs
109+
route.Priority = ptr.To(int64(rule.Priority))
110+
route.RemoteAddrs = rule.Match.RemoteAddrs
111111
route.Timeout = timeout
112-
route.Uris = http.Match.Paths
112+
route.Uris = rule.Match.Paths
113113
route.Vars = vars
114114

115115
// translate to adc.Upstream
116116
var backendErr error
117-
for _, backend := range http.Backends {
117+
for _, backend := range rule.Backends {
118118
weight := int32(*cmp.Or(backend.Weight, ptr.To(apiv2.DefaultWeight)))
119119
backendRef := gatewayv1.BackendRef{
120120
BackendObjectReference: gatewayv1.BackendObjectReference{
@@ -135,15 +135,15 @@ func (t *Translator) TranslateApisixRoute(tctx *provider.TranslateContext, ar *a
135135
upstream.Nodes = append(upstream.Nodes, upNodes...)
136136
}
137137
//nolint:staticcheck
138-
if len(http.Backends) == 0 && len(http.Upstreams) > 0 {
138+
if len(rule.Backends) == 0 && len(rule.Upstreams) > 0 {
139139
// FIXME: when the API ApisixUpstream is supported
140140
}
141141

142142
// translate to adc.Service
143143
service.Name = adc.ComposeServiceNameWithRule(ar.Namespace, ar.Name, fmt.Sprintf("%d", ruleIndex))
144144
service.ID = id.GenID(service.Name)
145145
service.Labels = label.GenLabel(ar)
146-
service.Hosts = http.Match.Hosts
146+
service.Hosts = rule.Match.Hosts
147147
service.Upstream = upstream
148148
service.Routes = []*adc.Route{route}
149149

0 commit comments

Comments
 (0)