Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add generation of gateway-api coverage data #47

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions implementation/cilium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ EOF
run::cilium::conformance() {
echo "run::cilium::conformance"

if [[ ! -d ${IMPLEMENTATION_REPO_PATH} ]]; then
echo "IMPLEMENTATION_REPO_PATH: ${IMPLEMENTATION_REPO_PATH}"
echo "Repo for \"${IMPLEMENTATION}\" doesn't exists, cloning repo"

mkdir -p repos
cd $_ || exit
git clone https://github.com/cilium/cilium.git
cd - || exit
fi
pushd repos/cilium || exit 1

git checkout ${IMPLEMENTATION_VERSION}
mkdir -p repos
cd $_ || exit
[ -d "gateway-api-${GATEWAY_API_VERSION}" ] || git clone https://github.com/kubernetes-sigs/gateway-api.git gateway-api-"${GATEWAY_API_VERSION}"
cd - || exit
pushd repos/gateway-api-"${GATEWAY_API_VERSION}" || exit 1
git reset --hard HEAD
git checkout "${GATEWAY_API_VERSION}"
git apply ../../lib/gateway-api-"${GATEWAY_API_VERSION}"-useragent.patch

case ${GATEWAY_API_VERSION} in

Expand All @@ -60,8 +56,8 @@ run::cilium::conformance() {
;;

"v1.1.0")
CONFORMANCE_PROFILES="HTTP,TLS"
SUPPORTED_FEATURES="ReferenceGrant,HTTPRoute,TLSRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,GatewayClassObservedGenerationBump,HTTPRouteHostRewrite,HTTPRoutePathRewrite,HTTPRouteSchemeRedirect,HTTPRoutePathRedirect,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteRequestMultipleMirrors"
CONFORMANCE_PROFILES="GATEWAY-HTTP,GATEWAY-TLS"
EXEMPT_FEATURES="GatewayStaticAddresses,HTTPRouteParentRefPort,MeshConsumerRoute"
;;

*)
Expand All @@ -75,20 +71,20 @@ run::cilium::conformance() {

GATEWAY_API_CONFORMANCE_TESTS=1 go test \
-p 4 \
-v ./operator/pkg/gateway-api \
./conformance/ \
--gateway-class cilium \
--supported-features "${SUPPORTED_FEATURES:-}" \
--exempt-features="${EXEMPT_FEATURES:-""}" \
--conformance-profiles="${CONFORMANCE_PROFILES:-""}" \
--report-output=${REPORT} \
--organization=cilium \
--project=cilium \
--url=https://github.com/cilium/cilium \
--version="$IMPLEMENTATION_VERSION" \
--contact='https://github.com/cilium/community/blob/main/roles/Maintainers.md' \
--supported-features="${SUPPORTED_FEATURES:-""}" \
--exempt-features="${EXEMPT_FEATURES:-""}" \
--conformance-profiles="${CONFORMANCE_PROFILES:-""}" \
--url=https://cilium.io/ \
--version="${IMPLEMENTATION_VERSION}" \
--contact='@cilium/maintainers' \
-test.run "TestConformance" \
-test.skip "${SKIP_TESTS:-""}" \
${ALL_FEATURES:-""}
-test.skip "${SKIP_TESTS:-}" \
-test.v 10

popd || exit

Expand Down
24 changes: 10 additions & 14 deletions implementation/contour.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ run::contour::conformance() {
run::contour::gateway-api-conformance() {
echo "run::contour::gateway-api-conformance"

export GATEWAY_API_REPO_PATH=${GATEWAY_API_REPO_PATH:-"${PWD}/repos/gateway-api}"}
if [[ ! -d ${GATEWAY_API_REPO_PATH} ]]; then
echo "GATEWAY_API_REPO_PATH: ${GATEWAY_API_REPO_PATH}"
echo "Repo doesn't exists, cloning repo"

mkdir -p repos
cd $_ || exit
git clone https://github.com/kubernetes-sigs/gateway-api.git || true
cd - || exit
fi
pushd repos/gateway-api/conformance || exit 1

git checkout ${GATEWAY_API_VERSION}
mkdir -p repos
cd $_ || exit
[ -d "gateway-api-${GATEWAY_API_VERSION}" ] || git clone https://github.com/kubernetes-sigs/gateway-api.git gateway-api-"${GATEWAY_API_VERSION}"
cd - || exit
pushd repos/gateway-api-"${GATEWAY_API_VERSION}" || exit 1
git reset --hard HEAD
git checkout "${GATEWAY_API_VERSION}"
git apply ../../lib/gateway-api-"${GATEWAY_API_VERSION}"-useragent.patch

SUPPORTED_FEATURES="Gateway,HTTPRoute"
SKIP_TESTS="Mesh"
Expand All @@ -63,6 +58,7 @@ run::contour::gateway-api-conformance() {

GATEWAY_API_CONFORMANCE_TESTS=1 go test \
-p 4 \
./conformance/ \
--gateway-class contour \
--supported-features "${SUPPORTED_FEATURES}" \
--report-output=${REPORT} \
Expand All @@ -72,7 +68,7 @@ run::contour::gateway-api-conformance() {
--version=v1.29.0 \
--contact='@projectcontour/maintainers' \
-test.run "TestConformance" \
-test.skip "${SKIP_TESTS}" \
-test.skip "${SKIP_TESTS:-}" \
-test.v 10

popd || exit
Expand Down
24 changes: 10 additions & 14 deletions implementation/envoy-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ run::envoy-gateway::conformance() {
run::envoy-gateway::gateway-api-conformance() {
echo "run::envoy-gateway::gateway-api-conformance"

export GATEWAY_API_REPO_PATH=${GATEWAY_API_REPO_PATH:-"${PWD}/repos/gateway-api}"}
if [[ ! -d ${GATEWAY_API_REPO_PATH} ]]; then
echo "GATEWAY_API_REPO_PATH: ${GATEWAY_API_REPO_PATH}"
echo "Repo doesn't exists, cloning repo"

mkdir -p repos
cd $_ || exit
git clone https://github.com/kubernetes-sigs/gateway-api.git
cd - || exit
fi
pushd repos/gateway-api/conformance || exit 1

git checkout ${GATEWAY_API_VERSION}
mkdir -p repos
cd $_ || exit
[ -d "gateway-api-${GATEWAY_API_VERSION}" ] || git clone https://github.com/kubernetes-sigs/gateway-api.git gateway-api-"${GATEWAY_API_VERSION}"
cd - || exit
pushd repos/gateway-api-"${GATEWAY_API_VERSION}" || exit 1
git reset --hard HEAD
git checkout "${GATEWAY_API_VERSION}"
git apply ../../lib/gateway-api-"${GATEWAY_API_VERSION}"-useragent.patch

SUPPORTED_FEATURES="Gateway,HTTPRoute"
SKIP_TESTS="Mesh"
Expand All @@ -42,6 +37,7 @@ run::envoy-gateway::gateway-api-conformance() {

GATEWAY_API_CONFORMANCE_TESTS=1 go test \
-p 4 \
./conformance \
--gateway-class eg \
--supported-features "${SUPPORTED_FEATURES}" \
--report-output=${REPORT} \
Expand All @@ -51,7 +47,7 @@ run::envoy-gateway::gateway-api-conformance() {
--version=v1.0.1 \
--contact=https://github.com/envoyproxy/gateway/blob/main/GOVERNANCE.md \
-test.run "TestConformance" \
-test.skip "${SKIP_TESTS}" \
-test.skip "${SKIP_TESTS:-}" \
-test.v 10

popd || exit
Expand Down
47 changes: 21 additions & 26 deletions implementation/istio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,34 @@ EOF
run::istio::conformance() {
echo "run::istio::conformance"

if [[ ! -d ${IMPLEMENTATION_REPO_PATH} ]]; then
echo "IMPLEMENTATION_REPO_PATH: ${IMPLEMENTATION_REPO_PATH}"
echo "Repo for \"${IMPLEMENTATION}\" doesn't exists, cloning repo"

mkdir -p repos
cd $_ || exit
git clone https://github.com/istio/istio.git
cd - || exit
fi
pushd repos/istio || exit 1
git fetch --tags -a
git checkout "$IMPLEMENTATION_VERSION"
mkdir -p repos
cd $_ || exit
[ -d "gateway-api-${GATEWAY_API_VERSION}" ] || git clone https://github.com/kubernetes-sigs/gateway-api.git gateway-api-"${GATEWAY_API_VERSION}"
cd - || exit
pushd repos/gateway-api-"${GATEWAY_API_VERSION}" || exit 1
git reset --hard HEAD
git checkout "${GATEWAY_API_VERSION}"
git apply ../../lib/gateway-api-"${GATEWAY_API_VERSION}"-useragent.patch

SUPPORTED_FEATURES="Gateway,HTTPRoute,HTTPRouteDestinationPortMatching,HTTPRouteHostRewrite,HTTPRouteMethodMatching,HTTPRoutePathRedirect,HTTPRoutePathRewrite,HTTPRoutePortRedirect,HTTPRouteQueryParamMatching,HTTPRouteRequestMirror,HTTPRouteRequestMultipleMirrors,HTTPRouteResponseHeaderModification,HTTPRouteSchemeRedirect,ReferenceGrant,TLSRoute"
SKIP_TESTS=""
CURRENT_DATE_TIME=$(date +"%Y%m%d-%H%M")
REPORT="/tmp/conformance-suite-report-${CURRENT_DATE_TIME}-istio.yaml"

go test \
-v -timeout 60m \
-run TestGatewayConformance \
-skip "$SKIP_TESTS" \
./tests/integration/pilot \
-tags=integ \
--gateway-class=istio \
--all-features \
--contact='@istio/maintainers' \
--version="$IMPLEMENTATION_VERSION" \
--report-output="$REPORT" \
--url="https://istio.io" \
--project=istio \
GATEWAY_API_CONFORMANCE_TESTS=1 go test \
-p 4 \
./conformance/ \
--gateway-class istio \
--supported-features "${SUPPORTED_FEATURES:-}" \
--report-output=${REPORT} \
--organization=istio \
--supported-features="$SUPPORTED_FEATURES"
--project=istio \
--url=https://istio.io/ \
--version="$IMPLEMENTATION_VERSION" \
--contact='@istio/maintainers' \
-test.run "TestConformance" \
-test.skip "${SKIP_TESTS:-}" \
-test.v 10

popd || exit

Expand Down
86 changes: 86 additions & 0 deletions lib/gateway-api-v1.0.0-useragent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go
index bbd65634..9ec86970 100644
--- a/conformance/conformance_test.go
+++ b/conformance/conformance_test.go
@@ -38,6 +38,7 @@ func TestConformance(t *testing.T) {
if err != nil {
t.Fatalf("Error loading Kubernetes config: %v", err)
}
+ cfg.UserAgent = "gateway-api-conformance.test::v1.0.0::unknownTest::unknownFeature"
client, err := client.New(cfg, client.Options{})
if err != nil {
t.Fatalf("Error initializing Kubernetes client: %v", err)
diff --git a/conformance/utils/suite/suite.go b/conformance/utils/suite/suite.go
index 58a55624..be8e1c8f 100644
--- a/conformance/utils/suite/suite.go
+++ b/conformance/utils/suite/suite.go
@@ -21,10 +21,12 @@ import (
"strings"
"testing"

+ "github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/sets"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
+ clicfg "sigs.k8s.io/controller-runtime/pkg/client/config"

"sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/gateway-api/conformance"
@@ -157,6 +159,10 @@ func New(s Options) *ConformanceTestSuite {
return suite
}

+const (
+ testSuiteUserAgentPrefix = "gateway-api-conformance.test"
+)
+
// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T) {
@@ -206,10 +212,45 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
}
}

+func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
+ cfg, err := clicfg.GetConfig()
+ if err != nil {
+ return err
+ }
+ featureNames := []string{}
+ for _, v := range test.Features {
+ featureNames = append(featureNames, string(v))
+ }
+ if len(test.Features) == 0 {
+ featureNames = []string{"unknownFeature"}
+ }
+ cfg.UserAgent = strings.Join(
+ []string{
+ testSuiteUserAgentPrefix,
+ "v1.0.0", // NOTE version not exported in v1.0.0
+ test.ShortName,
+ strings.Join(featureNames, ","),
+ },
+ "::")
+ client, err := client.New(cfg, client.Options{})
+ if err != nil {
+ return err
+ }
+ clientset, err := clientset.NewForConfig(cfg)
+ if err != nil {
+ return err
+ }
+ suite.Client = client
+ suite.Clientset = clientset
+ return nil
+}
+
// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) {
for _, test := range tests {
t.Run(test.ShortName, func(t *testing.T) {
+ err := suite.setClientsetForTest(test)
+ require.NoError(t, err, "failed to create new clientset for test")
test.Run(t, suite)
})
}
72 changes: 72 additions & 0 deletions lib/gateway-api-v1.1.0-useragent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
diff --git a/conformance/utils/suite/suite.go b/conformance/utils/suite/suite.go
index 3e6e1a07..0c937ebb 100644
--- a/conformance/utils/suite/suite.go
+++ b/conformance/utils/suite/suite.go
@@ -35,6 +35,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
+ clicfg "sigs.k8s.io/controller-runtime/pkg/client/config"

"sigs.k8s.io/gateway-api/apis/v1beta1"
confv1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
@@ -307,6 +308,10 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
// Conformance Test Suite - Public Methods
// -----------------------------------------------------------------------------

+const (
+ testSuiteUserAgentPrefix = "gateway-api-conformance.test"
+)
+
// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest) {
@@ -374,6 +379,39 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
}
}

+func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
+ cfg, err := clicfg.GetConfig()
+ if err != nil {
+ return err
+ }
+ featureNames := []string{}
+ for _, v := range test.Features {
+ featureNames = append(featureNames, string(v))
+ }
+ if len(test.Features) == 0 {
+ featureNames = []string{"unknownFeature"}
+ }
+ cfg.UserAgent = strings.Join(
+ []string{
+ testSuiteUserAgentPrefix,
+ suite.apiVersion,
+ test.ShortName,
+ strings.Join(featureNames, ","),
+ },
+ "::")
+ client, err := client.New(cfg, client.Options{})
+ if err != nil {
+ return err
+ }
+ clientset, err := clientset.NewForConfig(cfg)
+ if err != nil {
+ return err
+ }
+ suite.Client = client
+ suite.Clientset = clientset
+ return nil
+}
+
// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) error {
// verify that the test suite isn't already running, don't start a new run
@@ -394,6 +432,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
results := make(map[string]testResult)
for _, test := range tests {
succeeded := t.Run(test.ShortName, func(t *testing.T) {
+ err := suite.setClientsetForTest(test)
+ require.NoError(t, err, "failed to create new clientset for test")
test.Run(t, suite)
})
res := testSucceeded