Skip to content

Commit 921dd00

Browse files
authored
Generate conformance report and upload to release (#1017)
Problem: We want to be able to upload our conformance report for every release, so we can keep the upstream Gateway API tracker for our project up to date. Solution: Generate the conformance report whenever the tests are run. When a release occurs, we'll upload to the release artifacts.
1 parent 37490ef commit 921dd00

File tree

5 files changed

+72
-32
lines changed

5 files changed

+72
-32
lines changed

.github/workflows/conformance.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- main
77
- release-*
8+
tags:
9+
- "v[0-9]+.[0-9]+.[0-9]+*"
810
pull_request:
911
branches:
1012
- main
@@ -27,6 +29,8 @@ jobs:
2729
conformance-tests:
2830
name: Gateway Conformance Tests
2931
runs-on: ubuntu-22.04
32+
permissions:
33+
contents: write # needed for uploading release artifacts
3034
steps:
3135
- name: Checkout Repository
3236
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
@@ -139,5 +143,20 @@ jobs:
139143
working-directory: ./conformance
140144

141145
- name: Run conformance tests
142-
run: make run-conformance-tests TAG=${{ github.sha }}
146+
run: make run-conformance-tests TAG=${{ github.sha }} VERSION=${{ github.ref_name }}
147+
working-directory: ./conformance
148+
149+
- name: Wait for release to exist
150+
if: startsWith(github.ref, 'refs/tags/')
151+
uses: lewagon/wait-on-check-action@e106e5c43e8ca1edea6383a39a01c5ca495fd812 # v1.3.1
152+
with:
153+
ref: ${{ github.ref }}
154+
check-name: 'Build Binary'
155+
repo-token: ${{ secrets.GITHUB_TOKEN }}
156+
157+
- name: Upload profile to release
158+
if: startsWith(github.ref, 'refs/tags/')
159+
env:
160+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161+
run: gh release upload ${{ github.ref_name }} conformance-profile.yaml
143162
working-directory: ./conformance

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313
cover.html
14+
conformance/conformance-profile.yaml
1415

1516
# Dependency directories (remove the comment below to include it)
1617
# vendor/

conformance/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ run-conformance-tests: ## Run conformance tests
7676
kubectl run -i conformance \
7777
--image=$(PREFIX):$(TAG) --image-pull-policy=Never \
7878
--overrides='{ "spec": { "serviceAccountName": "conformance" } }' \
79-
--restart=Never -- go test -v . -tags conformance -args --gateway-class=$(GATEWAY_CLASS) --debug \
80-
--supported-features=$(SUPPORTED_FEATURES)
79+
--restart=Never -- sh -c "go test -v . -tags conformance,experimental -args --gateway-class=$(GATEWAY_CLASS) \
80+
--supported-features=$(SUPPORTED_FEATURES) --version=$(VERSION) \
81+
--report-output=output.txt; cat output.txt" | tee output.txt
82+
sed -e '1,/CONFORMANCE PROFILE/d' output.txt > conformance-profile.yaml
83+
rm output.txt
8184

8285
.PHONY: cleanup-conformance-tests
8386
cleanup-conformance-tests: ## Clean up conformance tests fixtures

conformance/tests/conformance_test.go

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818
package tests
1919

2020
import (
21-
"strings"
21+
"os"
2222
"testing"
2323

2424
. "github.com/onsi/gomega"
@@ -27,9 +27,11 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/client/config"
2828
"sigs.k8s.io/gateway-api/apis/v1alpha2"
2929
"sigs.k8s.io/gateway-api/apis/v1beta1"
30+
"sigs.k8s.io/gateway-api/conformance/apis/v1alpha1"
3031
"sigs.k8s.io/gateway-api/conformance/tests"
3132
"sigs.k8s.io/gateway-api/conformance/utils/flags"
3233
"sigs.k8s.io/gateway-api/conformance/utils/suite"
34+
"sigs.k8s.io/yaml"
3335
)
3436

3537
func TestConformance(t *testing.T) {
@@ -43,39 +45,54 @@ func TestConformance(t *testing.T) {
4345
g.Expect(v1alpha2.AddToScheme(client.Scheme())).To(Succeed())
4446
g.Expect(v1beta1.AddToScheme(client.Scheme())).To(Succeed())
4547

46-
supportedFeatures := parseSupportedFeatures(*flags.SupportedFeatures)
47-
exemptFeatures := parseSupportedFeatures(*flags.ExemptFeatures)
48+
supportedFeatures := suite.ParseSupportedFeatures(*flags.SupportedFeatures)
49+
exemptFeatures := suite.ParseSupportedFeatures(*flags.ExemptFeatures)
4850

4951
t.Logf(`Running conformance tests with %s GatewayClass\n cleanup: %t\n`+
5052
`debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]`,
5153
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug,
5254
*flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures)
5355

54-
cSuite := suite.New(suite.Options{
55-
Client: client,
56-
GatewayClassName: *flags.GatewayClassName,
57-
Debug: *flags.ShowDebug,
58-
CleanupBaseResources: *flags.CleanupBaseResources,
59-
SupportedFeatures: supportedFeatures,
60-
ExemptFeatures: exemptFeatures,
61-
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures,
56+
expSuite, err := suite.NewExperimentalConformanceTestSuite(suite.ExperimentalConformanceOptions{
57+
Options: suite.Options{
58+
Client: client,
59+
GatewayClassName: *flags.GatewayClassName,
60+
Debug: *flags.ShowDebug,
61+
CleanupBaseResources: *flags.CleanupBaseResources,
62+
SupportedFeatures: supportedFeatures,
63+
ExemptFeatures: exemptFeatures,
64+
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures,
65+
},
66+
Implementation: v1alpha1.Implementation{
67+
Organization: "nginxinc",
68+
Project: "nginx-kubernetes-gateway",
69+
URL: "https://github.com/nginxinc/nginx-kubernetes-gateway",
70+
Version: *flags.ImplementationVersion,
71+
Contact: []string{
72+
"https://github.com/nginxinc/nginx-kubernetes-gateway/discussions/new/choose",
73+
},
74+
},
75+
ConformanceProfiles: sets.New(suite.HTTPConformanceProfileName),
6276
})
63-
cSuite.Setup(t)
64-
cSuite.Run(t, tests.ConformanceTests)
65-
}
77+
g.Expect(err).To(Not(HaveOccurred()))
78+
79+
expSuite.Setup(t)
80+
err = expSuite.Run(t, tests.ConformanceTests)
81+
g.Expect(err).To(Not(HaveOccurred()))
82+
83+
report, err := expSuite.Report()
84+
g.Expect(err).To(Not(HaveOccurred()))
85+
86+
yamlReport, err := yaml.Marshal(report)
87+
g.Expect(err).ToNot(HaveOccurred())
88+
89+
f, err := os.Create(*flags.ReportOutput)
90+
g.Expect(err).ToNot(HaveOccurred())
91+
defer f.Close()
92+
93+
_, err = f.WriteString("CONFORMANCE PROFILE\n")
94+
g.Expect(err).ToNot(HaveOccurred())
6695

67-
// parseSupportedFeatures parses flag arguments and converts the string to
68-
// sets.Set[suite.SupportedFeature]
69-
// FIXME(kate-osborn): Use exported ParseSupportedFeatures function
70-
// https://github.com/kubernetes-sigs/gateway-api/blob/63e423cf1b837991d2747742199d90863a98b0c3/conformance/utils/suite/suite.go#L235
71-
// once it's released. https://github.com/nginxinc/nginx-kubernetes-gateway/issues/779
72-
func parseSupportedFeatures(f string) sets.Set[suite.SupportedFeature] {
73-
if f == "" {
74-
return nil
75-
}
76-
res := sets.Set[suite.SupportedFeature]{}
77-
for _, value := range strings.Split(f, ",") {
78-
res.Insert(suite.SupportedFeature(value))
79-
}
80-
return res
96+
_, err = f.Write(yamlReport)
97+
g.Expect(err).ToNot(HaveOccurred())
8198
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
sigs.k8s.io/controller-runtime v0.16.0
2222
sigs.k8s.io/controller-tools v0.13.0
2323
sigs.k8s.io/gateway-api v0.8.0
24+
sigs.k8s.io/yaml v1.3.0
2425
)
2526

2627
require (
@@ -88,5 +89,4 @@ require (
8889
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
8990
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
9091
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
91-
sigs.k8s.io/yaml v1.3.0 // indirect
9292
)

0 commit comments

Comments
 (0)