Skip to content

Commit 6a20c0b

Browse files
committed
Merge branch 'release-v2-dev' into fix/match-port
2 parents aecf533 + 90aff0b commit 6a20c0b

37 files changed

+368
-256
lines changed

.github/workflows/conformance-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
run: |
3333
go install sigs.k8s.io/[email protected]
3434
35+
- name: Install Helm
36+
run: |
37+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
38+
chmod 700 get_helm.sh
39+
./get_helm.sh
40+
3541
conformance-test:
3642
needs:
3743
- prepare
@@ -81,6 +87,10 @@ jobs:
8187
run: |
8288
make kind-load-images
8389
90+
- name: Install API7EE3
91+
run: |
92+
make download-api7ee3-chart
93+
8494
- name: Run Conformance Test
8595
shell: bash
8696
env:

.github/workflows/e2e-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
run: |
3333
go install sigs.k8s.io/[email protected]
3434
35+
- name: Install Helm
36+
run: |
37+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
38+
chmod 700 get_helm.sh
39+
./get_helm.sh
40+
3541
e2e-test:
3642
needs:
3743
- prepare
@@ -72,6 +78,10 @@ jobs:
7278
run: |
7379
make install
7480
81+
- name: Download API7EE3 Chart
82+
run: |
83+
make download-api7ee3-chart
84+
7585
- name: Loading Docker Image to Kind Cluster
7686
run: |
7787
make kind-load-images

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ api7-ingress-controller-conformance-report.yaml
3434
*.mdx
3535
.cursor/
3636
.env
37+
38+
charts/api7ee3

.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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ e2e-test:
106106
@kind get kubeconfig --name $(KIND_NAME) > $$KUBECONFIG
107107
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test ./test/e2e/ -test.timeout=$(TEST_TIMEOUT) -v -ginkgo.v -ginkgo.focus="$(TEST_FOCUS)"
108108

109+
.PHONY: download-api7ee3-chart
110+
download-api7ee3-chart:
111+
@helm repo add api7 https://charts.api7.ai || true
112+
@helm repo update
113+
@helm pull api7/api7ee3 --destination "$(shell helm env HELM_REPOSITORY_CACHE)"
114+
@echo "Downloaded API7EE3 chart"
115+
109116
.PHONY: conformance-test
110117
conformance-test:
111118
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test -v ./test/conformance -tags=conformance
@@ -278,7 +285,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
278285
KUSTOMIZE_VERSION ?= v5.4.2
279286
CONTROLLER_TOOLS_VERSION ?= v0.15.0
280287
ENVTEST_VERSION ?= release-0.18
281-
GOLANGCI_LINT_VERSION ?= v1.59.1
288+
GOLANGCI_LINT_VERSION ?= v2.1.5
282289

283290
.PHONY: kustomize
284291
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -298,7 +305,7 @@ $(ENVTEST): $(LOCALBIN)
298305
.PHONY: golangci-lint
299306
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
300307
$(GOLANGCI_LINT): $(LOCALBIN)
301-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
308+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
302309

303310
gofmt: ## Apply go fmt
304311
@gofmt -w -r 'interface{} -> any' .

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
}

internal/controller/consumer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool {
307307
return false
308308
}
309309
gatewayClass := &gatewayv1.GatewayClass{}
310-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
310+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
311311
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
312312
return false
313313
}

internal/controller/gateway_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate
208208
func (r *GatewayReconciler) checkGatewayClass(obj client.Object) bool {
209209
gateway := obj.(*gatewayv1.Gateway)
210210
gatewayClass := &gatewayv1.GatewayClass{}
211-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
211+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
212212
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
213213
return false
214214
}

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)