Skip to content

Commit 30e7cfe

Browse files
committed
fix lint
1 parent b2c608a commit 30e7cfe

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

api/adc/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ const (
7777
PassHostRewrite = "rewrite"
7878
)
7979

80+
const (
81+
TypeRoute = "route"
82+
TypeService = "service"
83+
TypeConsumer = "consumer"
84+
TypeSSL = "ssl"
85+
TypeGlobalRule = "global_rule"
86+
TypePluginMetadata = "plugin_metadata"
87+
)
88+
8089
type Object interface {
8190
GetLabels() map[string]string
8291
}

internal/provider/adc/adc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func (d *adcClient) resolveADCExecutionErrors(statusesMap map[string]types.ADCEx
451451
for _, execErr := range execErrors.Errors {
452452
for _, failedStatus := range execErr.FailedErrors {
453453
if len(failedStatus.FailedStatuses) == 0 {
454-
resouce, err := d.store.GetResources(execErr.Name) // ensure the config exists in store
454+
resource, err := d.store.GetResources(execErr.Name)
455455
if err != nil {
456456
log.Errorw("failed to get resources from store", zap.String("configName", configName), zap.Error(err))
457457
continue
@@ -470,15 +470,15 @@ func (d *adcClient) resolveADCExecutionErrors(statusesMap map[string]types.ADCEx
470470
statusUpdateMap[statusKey] = []string{failedStatus.Error()}
471471
}
472472
}
473-
for _, service := range resouce.Services {
473+
for _, service := range resource.Services {
474474
fillStatusUpdateMapFunc(service)
475475
}
476476

477-
for _, consumer := range resouce.Consumers {
477+
for _, consumer := range resource.Consumers {
478478
fillStatusUpdateMapFunc(consumer)
479479
}
480480

481-
for _, ssl := range resouce.SSLs {
481+
for _, ssl := range resource.SSLs {
482482
fillStatusUpdateMapFunc(ssl)
483483
}
484484

internal/provider/adc/store.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/google/uuid"
2626
"go.uber.org/zap"
2727

28-
"github.com/apache/apisix-ingress-controller/api/adc"
2928
adctypes "github.com/apache/apisix-ingress-controller/api/adc"
3029
"github.com/apache/apisix-ingress-controller/internal/controller/label"
3130
"github.com/apache/apisix-ingress-controller/internal/provider/adc/cache"
@@ -65,7 +64,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
6564
}
6665
for _, resourceType := range resourceTypes {
6766
switch resourceType {
68-
case "service":
67+
case adctypes.TypeService:
6968
services, err := targetCache.ListServices(selector)
7069
if err != nil {
7170
return err
@@ -80,7 +79,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
8079
return err
8180
}
8281
}
83-
case "consumer":
82+
case adctypes.TypeConsumer:
8483
consumers, err := targetCache.ListConsumers(selector)
8584
if err != nil {
8685
return err
@@ -95,7 +94,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
9594
return err
9695
}
9796
}
98-
case "ssl":
97+
case adctypes.TypeSSL:
9998
ssls, err := targetCache.ListSSL(selector)
10099
if err != nil {
101100
return err
@@ -111,7 +110,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
111110
return err
112111
}
113112
}
114-
case "global_rule":
113+
case adctypes.TypeGlobalRule:
115114
// List existing global rules that match the selector
116115
globalRules, err := targetCache.ListGlobalRules(selector)
117116
if err != nil {
@@ -138,7 +137,7 @@ func (s *Store) Insert(name string, resourceTypes []string, resources adctypes.R
138137
return err
139138
}
140139
}
141-
case "plugin_metadata":
140+
case adctypes.TypePluginMetadata:
142141
s.pluginMetadataMap[name] = resources.PluginMetadata
143142
default:
144143
continue
@@ -161,7 +160,7 @@ func (s *Store) Delete(name string, resourceTypes []string, Labels map[string]st
161160
}
162161
for _, resourceType := range resourceTypes {
163162
switch resourceType {
164-
case "service":
163+
case adctypes.TypeService:
165164
services, err := targetCache.ListServices(selector)
166165
if err != nil {
167166
log.Errorw("failed to list services", zap.Error(err))
@@ -171,7 +170,7 @@ func (s *Store) Delete(name string, resourceTypes []string, Labels map[string]st
171170
log.Errorw("failed to delete service", zap.Error(err), zap.String("service", service.ID))
172171
}
173172
}
174-
case "ssl":
173+
case adctypes.TypeSSL:
175174
ssls, err := targetCache.ListSSL(selector)
176175
if err != nil {
177176
log.Errorw("failed to list ssl", zap.Error(err))
@@ -181,7 +180,7 @@ func (s *Store) Delete(name string, resourceTypes []string, Labels map[string]st
181180
log.Errorw("failed to delete ssl", zap.Error(err), zap.String("ssl", ssl.ID))
182181
}
183182
}
184-
case "consumer":
183+
case adctypes.TypeConsumer:
185184
consumers, err := targetCache.ListConsumers(selector)
186185
if err != nil {
187186
log.Errorw("failed to list consumers", zap.Error(err))
@@ -191,7 +190,7 @@ func (s *Store) Delete(name string, resourceTypes []string, Labels map[string]st
191190
log.Errorw("failed to delete consumer", zap.Error(err), zap.String("consumer", consumer.Username))
192191
}
193192
}
194-
case "global_rule":
193+
case adctypes.TypeGlobalRule:
195194
globalRules, err := targetCache.ListGlobalRules(selector)
196195
if err != nil {
197196
log.Errorw("failed to list global rules", zap.Error(err))
@@ -201,7 +200,7 @@ func (s *Store) Delete(name string, resourceTypes []string, Labels map[string]st
201200
log.Errorw("failed to delete global rule", zap.Error(err), zap.String("global rule", globalRule.ID))
202201
}
203202
}
204-
case "plugin_metadata":
203+
case adctypes.TypePluginMetadata:
205204
delete(s.pluginMetadataMap, name)
206205
}
207206
}
@@ -319,6 +318,6 @@ func (s *Store) GetResourceLabel(name, resourceType string, id string) (map[stri
319318
return nil, nil
320319
}
321320

322-
func GetLabels(obj adc.Object) map[string]string {
321+
func GetLabels(obj adctypes.Object) map[string]string {
323322
return obj.GetLabels()
324323
}

internal/types/error.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323
"slices"
2424
"strings"
2525

26-
"github.com/apache/apisix-ingress-controller/api/adc"
2726
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
27+
28+
"github.com/apache/apisix-ingress-controller/api/adc"
2829
)
2930

3031
type ReasonError struct {
@@ -62,7 +63,7 @@ type ADCExecutionErrors struct {
6263
}
6364

6465
func (e ADCExecutionErrors) Error() string {
65-
var messages []string
66+
messages := make([]string, 0, len(e.Errors))
6667
for _, err := range e.Errors {
6768
messages = append(messages, err.Error())
6869
}
@@ -75,7 +76,7 @@ type ADCExecutionError struct {
7576
}
7677

7778
func (e ADCExecutionError) Error() string {
78-
var messages []string
79+
messages := make([]string, 0, len(e.FailedErrors))
7980
for _, failed := range e.FailedErrors {
8081
messages = append(messages, failed.Error())
8182
}

test/e2e/apisix/status.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package apisix
1919

2020
import (
2121
"fmt"
22+
"os"
2223
"time"
2324

2425
. "github.com/onsi/ginkgo/v2"
@@ -30,7 +31,7 @@ import (
3031
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
3132
)
3233

33-
var _ = Describe("Test ApisixRoute", Label("apisix.apache.org", "v2", "apisixroute"), func() {
34+
var _ = FDescribe("Test ApisixRoute", Label("apisix.apache.org", "v2", "apisixroute"), func() {
3435
var (
3536
s = scaffold.NewScaffold(&scaffold.Options{
3637
ControllerName: "apisix.apache.org/apisix-ingress-controller",
@@ -101,6 +102,9 @@ spec:
101102
}
102103

103104
It("unknown plugin", func() {
105+
if os.Getenv("PROVIDER_TYPE") == "apisix-standalone" {
106+
Skip("apisix standalone does not validate unknown plugins")
107+
}
104108
By("apply ApisixRoute with valid plugin")
105109
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, arWithInvalidPlugin)
106110

@@ -150,7 +154,7 @@ spec:
150154
)
151155

152156
By("check route in APISIX")
153-
assertion(getRequest("/get")).Should(Equal(401), "should be able to access the route")
157+
assertion(getRequest("/get")).Should(Equal(200), "should be able to access the route")
154158

155159
s.Deployer.ScaleDataplane(0)
156160
time.Sleep(10 * time.Second)

test/e2e/framework/manifests/ingress.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ data:
327327
controller_name: {{ .ControllerName | default "apisix.apache.org/apisix-ingress-controller" }}
328328
329329
leader_election_id: "apisix-ingress-controller-leader"
330+
331+
exec_adc_timeout: 3s # The timeout for the ADC to execute.
332+
330333
provider:
331334
type: {{ .ProviderType | default "apisix" }}
332335
sync_period: {{ .ProviderSyncPeriod | default "0s" }}

test/e2e/scaffold/apisix_deployer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (s *APISIXDeployer) DeployIngress() {
260260
s.Framework.DeployIngress(framework.IngressDeployOpts{
261261
ControllerName: s.opts.ControllerName,
262262
ProviderType: framework.ProviderType,
263-
ProviderSyncPeriod: 200 * time.Millisecond,
263+
ProviderSyncPeriod: 1 * time.Second,
264264
Namespace: s.namespace,
265265
Replicas: 1,
266266
})
@@ -270,7 +270,7 @@ func (s *APISIXDeployer) ScaleIngress(replicas int) {
270270
s.Framework.DeployIngress(framework.IngressDeployOpts{
271271
ControllerName: s.opts.ControllerName,
272272
ProviderType: framework.ProviderType,
273-
ProviderSyncPeriod: 200 * time.Millisecond,
273+
ProviderSyncPeriod: 1 * time.Second,
274274
Namespace: s.namespace,
275275
Replicas: replicas,
276276
})

0 commit comments

Comments
 (0)