Skip to content

Commit e365525

Browse files
authored
feat: support conformance test for apisix (#160)
Signed-off-by: ashing <[email protected]>
1 parent 3b50dd8 commit e365525

File tree

10 files changed

+521
-18
lines changed

10 files changed

+521
-18
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: APISIX Conformance Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release-v2-dev
8+
pull_request:
9+
branches:
10+
- master
11+
- release-v2-dev
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
prepare:
19+
name: Prepare
20+
runs-on: buildjet-2vcpu-ubuntu-2204
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Go Env
26+
id: go
27+
uses: actions/setup-go@v4
28+
with:
29+
go-version: "1.22"
30+
31+
- name: Install kind
32+
run: |
33+
go install sigs.k8s.io/[email protected]
34+
35+
conformance-test:
36+
timeout-minutes: 60
37+
needs:
38+
- prepare
39+
runs-on: buildjet-2vcpu-ubuntu-2204
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
submodules: recursive
45+
46+
- name: Setup Go Env
47+
uses: actions/setup-go@v4
48+
with:
49+
go-version: "1.22"
50+
51+
- name: Build images
52+
env:
53+
TAG: dev
54+
ARCH: amd64
55+
ENABLE_PROXY: "false"
56+
BASE_IMAGE_TAG: "debug"
57+
run: |
58+
echo "building images..."
59+
make build-image
60+
61+
- name: Launch Kind Cluster
62+
run: |
63+
make kind-up
64+
65+
- name: Install And Run Cloud Provider KIND
66+
run: |
67+
go install sigs.k8s.io/cloud-provider-kind@latest
68+
nohup cloud-provider-kind > /tmp/kind-loadbalancer.log 2>&1 &
69+
70+
- name: Install Gateway API And CRDs
71+
run: |
72+
make install
73+
74+
- name: Loading Docker Image to Kind Cluster
75+
run: |
76+
make kind-load-images
77+
78+
- name: Run Conformance Test
79+
shell: bash
80+
continue-on-error: true
81+
run: |
82+
make conformance-test-standalone
83+
84+
- name: Get Logs from api7-ingress-controller
85+
shell: bash
86+
run: |
87+
export KUBECONFIG=/tmp/apisix-ingress-cluster.kubeconfig
88+
kubectl logs -n apisix-conformance-test -l app=apisix-ingress-controller
89+
90+
- name: Upload Gateway API Conformance Report
91+
if: ${{ github.event_name == 'push' }}
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: apisix-ingress-controller-conformance-report.yaml
95+
path: apisix-ingress-controller-conformance-report.yaml
96+
97+
- name: Format Conformance Test Report
98+
if: ${{ github.event_name == 'pull_request' }}
99+
run: |
100+
echo '# conformance test report' > report.md
101+
echo '```yaml' >> report.md
102+
cat apisix-ingress-controller-conformance-report.yaml >> report.md
103+
echo '```' >> report.md
104+
105+
- name: Report Conformance Test Result to PR Comment
106+
if: ${{ github.event_name == 'pull_request' }}
107+
uses: mshick/add-pr-comment@v2
108+
with:
109+
message-id: '${{ matrix.target }}'
110+
message-path: |
111+
report.md

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ download-api7ee3-chart:
127127
conformance-test:
128128
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test -v ./test/conformance -tags=conformance -timeout 60m
129129

130+
.PHONY: conformance-test-standalone
131+
conformance-test-standalone:
132+
@kind get kubeconfig --name $(KIND_NAME) > $$KUBECONFIG
133+
go test -v ./test/conformance/apisix -tags=conformance -timeout 60m
134+
130135
.PHONY: lint
131136
lint: sort-import golangci-lint ## Run golangci-lint linter
132137
$(GOLANGCI_LINT) run
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//go:build conformance
2+
// +build conformance
3+
4+
package conformance
5+
6+
import (
7+
"flag"
8+
"os"
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
"k8s.io/apimachinery/pkg/util/sets"
13+
"sigs.k8s.io/gateway-api/conformance"
14+
conformancev1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
15+
"sigs.k8s.io/gateway-api/conformance/tests"
16+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
17+
"sigs.k8s.io/gateway-api/pkg/features"
18+
"sigs.k8s.io/yaml"
19+
)
20+
21+
var skippedTestsForSSL = []string{
22+
// Reason: https://github.com/kubernetes-sigs/gateway-api/blob/5c5fc388829d24e8071071b01e8313ada8f15d9f/conformance/utils/suite/suite.go#L358. SAN includes '*'
23+
tests.HTTPRouteHTTPSListener.ShortName,
24+
tests.HTTPRouteRedirectPortAndScheme.ShortName,
25+
}
26+
27+
// TODO: HTTPRoute hostname intersection and listener hostname matching
28+
29+
var gatewaySupportedFeatures = []features.FeatureName{
30+
features.SupportGateway,
31+
features.SupportHTTPRoute,
32+
// features.SupportHTTPRouteMethodMatching,
33+
// features.SupportHTTPRouteResponseHeaderModification,
34+
// features.SupportHTTPRouteRequestMirror,
35+
// features.SupportHTTPRouteBackendRequestHeaderModification,
36+
// features.SupportHTTPRouteHostRewrite,
37+
}
38+
39+
func TestGatewayAPIConformance(t *testing.T) {
40+
flag.Parse()
41+
42+
opts := conformance.DefaultOptions(t)
43+
opts.Debug = true
44+
opts.CleanupBaseResources = true
45+
opts.GatewayClassName = gatewayClassName
46+
opts.SupportedFeatures = sets.New(gatewaySupportedFeatures...)
47+
opts.SkipTests = skippedTestsForSSL
48+
opts.Implementation = conformancev1.Implementation{
49+
Organization: "APISIX",
50+
Project: "apisix-ingress-controller",
51+
URL: "https://github.com/apache/apisix-ingress-controller.git",
52+
Version: "v2.0.0",
53+
}
54+
opts.ConformanceProfiles = sets.New(suite.GatewayHTTPConformanceProfileName)
55+
56+
cSuite, err := suite.NewConformanceTestSuite(opts)
57+
require.NoError(t, err)
58+
59+
t.Log("starting the gateway conformance test suite")
60+
cSuite.Setup(t, tests.ConformanceTests)
61+
62+
if err := cSuite.Run(t, tests.ConformanceTests); err != nil {
63+
t.Fatalf("failed to run the gateway conformance test suite: %v", err)
64+
}
65+
66+
const reportFileName = "apisix-ingress-controller-conformance-report.yaml"
67+
report, err := cSuite.Report()
68+
if err != nil {
69+
t.Fatalf("failed to get the gateway conformance test report: %v", err)
70+
}
71+
72+
rawReport, err := yaml.Marshal(report)
73+
if err != nil {
74+
t.Fatalf("failed to marshal the gateway conformance test report: %v", err)
75+
}
76+
// Save report in the root of the repository, file name is in .gitignore.
77+
require.NoError(t, os.WriteFile("../../../"+reportFileName, rawReport, 0o600))
78+
}

0 commit comments

Comments
 (0)