Skip to content

Commit ca2c301

Browse files
committed
Merge branch origin/release-v2-dev
2 parents 662860d + 356694f commit ca2c301

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+866
-339
lines changed

.golangci.yml

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
227
- dupl
238
- errcheck
24-
- exportloopref
259
- ginkgolinter
2610
- goconst
2711
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3112
- govet
3213
- ineffassign
3314
- lll
@@ -36,12 +17,38 @@ linters:
3617
- prealloc
3718
- revive
3819
- staticcheck
39-
- typecheck
4020
- unconvert
4121
- unparam
4222
- unused
43-
44-
linters-settings:
45-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4629
rules:
47-
- name: comment-spacings
30+
- linters:
31+
- lll
32+
path: api/*
33+
- linters:
34+
- dupl
35+
- lll
36+
path: internal/*
37+
- linters:
38+
- staticcheck
39+
text: "ST1001:"
40+
path: test/.*
41+
paths:
42+
- third_party$
43+
- builtin$
44+
- examples$
45+
formatters:
46+
enable:
47+
- gofmt
48+
- goimports
49+
exclusions:
50+
generated: lax
51+
paths:
52+
- third_party$
53+
- builtin$
54+
- examples$

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ conformance-test:
118118
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test -v ./test/conformance -tags=conformance
119119

120120
.PHONY: lint
121-
lint: golangci-lint ## Run golangci-lint linter
121+
lint: sort-import golangci-lint ## Run golangci-lint linter
122122
$(GOLANGCI_LINT) run
123123

124124
.PHONY: lint-fix
@@ -286,7 +286,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
286286
KUSTOMIZE_VERSION ?= v5.4.2
287287
CONTROLLER_TOOLS_VERSION ?= v0.15.0
288288
ENVTEST_VERSION ?= release-0.18
289-
GOLANGCI_LINT_VERSION ?= v1.59.1
289+
GOLANGCI_LINT_VERSION ?= v2.1.5
290290

291291
.PHONY: kustomize
292292
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -306,7 +306,7 @@ $(ENVTEST): $(LOCALBIN)
306306
.PHONY: golangci-lint
307307
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
308308
$(GOLANGCI_LINT): $(LOCALBIN)
309-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
309+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
310310

311311
gofmt: ## Apply go fmt
312312
@gofmt -w -r 'interface{} -> any' .
@@ -343,3 +343,7 @@ helm-build-crds:
343343
$(KUSTOMIZE) build github.com/kubernetes-sigs/gateway-api/config/crd\?ref=${GATEAY_API_VERSION} > charts/crds/gwapi-crds.yaml
344344
@echo "build apisix ic crds"
345345
$(KUSTOMIZE) build config/crd > charts/crds/apisixic-crds.yaml
346+
347+
sort-import:
348+
@./scripts/goimports-reviser.sh >/dev/null 2>&1
349+
.PHONY: sort-import

api/dashboard/v1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ func ComposeConsumerName(namespace, name string) string {
730730
buf := bytes.NewBuffer(p)
731731

732732
// TODO If APISIX modifies the consumer name schema, we can drop this.
733-
buf.WriteString(strings.Replace(namespace, "-", "_", -1))
733+
buf.WriteString(strings.ReplaceAll(namespace, "-", "_"))
734734
buf.WriteString("_")
735-
buf.WriteString(strings.Replace(name, "-", "_", -1))
735+
buf.WriteString(strings.ReplaceAll(name, "-", "_"))
736736

737737
return buf.String()
738738
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
go.etcd.io/etcd/client/v3 v3.5.15
2828
go.uber.org/multierr v1.11.0
2929
go.uber.org/zap v1.27.0
30+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
3031
golang.org/x/net v0.28.0
3132
gopkg.in/yaml.v2 v2.4.0
3233
gorm.io/gorm v1.25.11
@@ -194,7 +195,6 @@ require (
194195
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
195196
golang.org/x/arch v0.6.0 // indirect
196197
golang.org/x/crypto v0.26.0 // indirect
197-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
198198
golang.org/x/mod v0.20.0 // indirect
199199
golang.org/x/oauth2 v0.21.0 // indirect
200200
golang.org/x/sync v0.8.0 // indirect

internal/controller/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"text/template"
1010
"time"
1111

12-
"github.com/api7/api7-ingress-controller/internal/types"
1312
"gopkg.in/yaml.v2"
13+
14+
"github.com/api7/api7-ingress-controller/internal/types"
1415
)
1516

1617
var (

internal/controller/consumer_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package controller
33
import (
44
"context"
55

6-
"github.com/api7/api7-ingress-controller/api/v1alpha1"
7-
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
8-
"github.com/api7/api7-ingress-controller/internal/provider"
96
"github.com/go-logr/logr"
107
corev1 "k8s.io/api/core/v1"
118
"k8s.io/apimachinery/pkg/api/meta"
@@ -20,6 +17,10 @@ import (
2017
"sigs.k8s.io/controller-runtime/pkg/predicate"
2118
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2219
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
20+
21+
"github.com/api7/api7-ingress-controller/api/v1alpha1"
22+
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
23+
"github.com/api7/api7-ingress-controller/internal/provider"
2324
)
2425

2526
// ConsumerReconciler reconciles a Gateway object.
@@ -307,7 +308,7 @@ func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool {
307308
return false
308309
}
309310
gatewayClass := &gatewayv1.GatewayClass{}
310-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
311+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
311312
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
312313
return false
313314
}

internal/controller/gateway_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import (
55
"fmt"
66
"reflect"
77

8-
"github.com/api7/api7-ingress-controller/api/v1alpha1"
9-
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
10-
"github.com/api7/api7-ingress-controller/internal/provider"
118
"github.com/api7/gopkg/pkg/log"
129
"github.com/go-logr/logr"
1310
corev1 "k8s.io/api/core/v1"
@@ -21,6 +18,10 @@ import (
2118
"sigs.k8s.io/controller-runtime/pkg/predicate"
2219
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2320
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
21+
22+
"github.com/api7/api7-ingress-controller/api/v1alpha1"
23+
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
24+
"github.com/api7/api7-ingress-controller/internal/provider"
2425
)
2526

2627
// GatewayReconciler reconciles a Gateway object.
@@ -208,7 +209,7 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate
208209
func (r *GatewayReconciler) checkGatewayClass(obj client.Object) bool {
209210
gateway := obj.(*gatewayv1.Gateway)
210211
gatewayClass := &gatewayv1.GatewayClass{}
211-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
212+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
212213
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
213214
return false
214215
}

internal/controller/gatewayclass_congroller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/api7/api7-ingress-controller/internal/controller/config"
87
"github.com/go-logr/logr"
98
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
109
"k8s.io/apimachinery/pkg/runtime"
1110
ctrl "sigs.k8s.io/controller-runtime"
1211
"sigs.k8s.io/controller-runtime/pkg/client"
1312
"sigs.k8s.io/controller-runtime/pkg/predicate"
1413
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
14+
15+
"github.com/api7/api7-ingress-controller/internal/controller/config"
1516
)
1617

1718
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses,verbs=get;list;watch;update

internal/controller/httproute_controller.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77

88
"github.com/go-logr/logr"
99
"github.com/pkg/errors"
10+
"golang.org/x/exp/slices"
1011
corev1 "k8s.io/api/core/v1"
1112
discoveryv1 "k8s.io/api/discovery/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/runtime"
1415
"k8s.io/apimachinery/pkg/types"
16+
"k8s.io/utils/ptr"
1517
ctrl "sigs.k8s.io/controller-runtime"
1618
"sigs.k8s.io/controller-runtime/pkg/builder"
1719
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -98,6 +100,9 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
98100
hr := new(gatewayv1.HTTPRoute)
99101
if err := r.Get(ctx, req.NamespacedName, hr); err != nil {
100102
if client.IgnoreNotFound(err) == nil {
103+
if err := r.updateHTTPRoutePolicyStatusOnDeleting(req.NamespacedName); err != nil {
104+
return ctrl.Result{}, err
105+
}
101106
hr.Namespace = req.Namespace
102107
hr.Name = req.Name
103108

@@ -514,21 +519,14 @@ func httpRoutePolicyPredicateFuncs(channel chan event.GenericEvent) predicate.Pr
514519
if !ok0 || !ok1 {
515520
return false
516521
}
517-
var discardsRefs = make(map[string]v1alpha2.LocalPolicyTargetReferenceWithSectionName)
518-
for _, ref := range oldPolicy.Spec.TargetRefs {
519-
key := indexer.GenHTTPRoutePolicyIndexKey(string(ref.Group), string(ref.Kind), e.ObjectOld.GetNamespace(), string(ref.Name), "")
520-
discardsRefs[key] = ref
521-
}
522-
for _, ref := range newPolicy.Spec.TargetRefs {
523-
key := indexer.GenHTTPRoutePolicyIndexKey(string(ref.Group), string(ref.Kind), e.ObjectOld.GetNamespace(), string(ref.Name), "")
524-
delete(discardsRefs, key)
525-
}
522+
discardsRefs := slices.DeleteFunc(oldPolicy.Spec.TargetRefs, func(oldRef v1alpha2.LocalPolicyTargetReferenceWithSectionName) bool {
523+
return slices.ContainsFunc(newPolicy.Spec.TargetRefs, func(newRef v1alpha2.LocalPolicyTargetReferenceWithSectionName) bool {
524+
return oldRef.LocalPolicyTargetReference == newRef.LocalPolicyTargetReference && ptr.Equal(oldRef.SectionName, newRef.SectionName)
525+
})
526+
})
526527
if len(discardsRefs) > 0 {
527528
dump := oldPolicy.DeepCopy()
528-
dump.Spec.TargetRefs = make([]v1alpha2.LocalPolicyTargetReferenceWithSectionName, 0, len(discardsRefs))
529-
for _, ref := range discardsRefs {
530-
dump.Spec.TargetRefs = append(dump.Spec.TargetRefs, ref)
531-
}
529+
dump.Spec.TargetRefs = discardsRefs
532530
channel <- event.GenericEvent{Object: dump}
533531
}
534532
return true

0 commit comments

Comments
 (0)