From 32ef482d881cd24b771554b91bb882548a05d154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Thu, 23 May 2024 15:21:53 +0200 Subject: [PATCH] tests: run conformance on CI --- .github/workflows/tests.yaml | 63 +++++++++---------- internal/types/gatewaytypes.go | 1 + test/conformance/conformance_test.go | 93 ++++++++++++++++++++++++++-- 3 files changed, 120 insertions(+), 37 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a76573ce6..863aaf7c9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -175,39 +175,36 @@ jobs: name: tests-report path: unit-tests.xml - # TODO: https://github.com/Kong/gateway-operator/issues/1411 - # conformance-tests: - # runs-on: ubuntu-latest - # steps: - # - name: checkout repository - # uses: actions/checkout@v4 - # with: - # fetch-depth: 0 - - # - name: setup golang - # uses: actions/setup-go@v5 - # with: - # go-version-file: go.mod - - # - name: run conformance tests - # run: make test.conformance - # env: - # GOTESTSUM_JUNITFILE: "conformance-tests.xml" - - # - name: upload diagnostics - # if: ${{ always() }} - # uses: actions/upload-artifact@v4 - # with: - # name: diagnostics-conformance - # path: /tmp/ktf-diag* - # if-no-files-found: ignore - - # - name: collect test report - # if: ${{ always() }} - # uses: actions/upload-artifact@v3 - # with: - # name: tests-report - # path: conformance-tests.xml + conformance-tests: + runs-on: ubuntu-latest + steps: + - name: checkout repository + uses: actions/checkout@v4 + + - name: setup golang + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: run conformance tests + run: make test.conformance + env: + GOTESTSUM_JUNITFILE: "conformance-tests.xml" + + - name: upload diagnostics + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: diagnostics-conformance + path: /tmp/ktf-diag* + if-no-files-found: ignore + + - name: collect test report + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: tests-report + path: conformance-tests.xml integration-tests: runs-on: ubuntu-latest diff --git a/internal/types/gatewaytypes.go b/internal/types/gatewaytypes.go index 885fcf6b9..1ec6b8885 100644 --- a/internal/types/gatewaytypes.go +++ b/internal/types/gatewaytypes.go @@ -16,6 +16,7 @@ type ( ParentReference = gatewayv1.ParentReference CommonRouteSpec = gatewayv1.CommonRouteSpec Kind = gatewayv1.Kind + Namespace = gatewayv1.Namespace Group = gatewayv1.Group AllowedRoutes = gatewayv1.AllowedRoutes RouteGroupKind = gatewayv1.RouteGroupKind diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index f187d2271..76a6fb081 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -4,8 +4,10 @@ import ( "path" "testing" - "github.com/google/uuid" + "github.com/samber/lo" "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" @@ -15,7 +17,9 @@ import ( "sigs.k8s.io/gateway-api/conformance/utils/suite" "sigs.k8s.io/gateway-api/pkg/features" + v1beta1 "github.com/kong/gateway-operator/api/v1beta1" "github.com/kong/gateway-operator/internal/metadata" + gwtypes "github.com/kong/gateway-operator/internal/types" testutils "github.com/kong/gateway-operator/pkg/utils/test" "github.com/kong/gateway-operator/pkg/vars" ) @@ -40,18 +44,99 @@ func TestGatewayConformance(t *testing.T) { t.Parallel() t.Log("creating GatewayClass for gateway conformance tests") + gwconf := v1beta1.GatewayConfiguration{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "kgo-gwconf-conformance-", + Namespace: "default", + }, + Spec: v1beta1.GatewayConfigurationSpec{ + DataPlaneOptions: &v1beta1.GatewayConfigDataPlaneOptions{ + Deployment: v1beta1.DataPlaneDeploymentOptions{ + DeploymentOptions: v1beta1.DeploymentOptions{ + PodTemplateSpec: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "proxy", + ReadinessProbe: &corev1.Probe{ + InitialDelaySeconds: 1, + PeriodSeconds: 1, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("1024Mi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + ControlPlaneOptions: &v1beta1.ControlPlaneOptions{ + Deployment: v1beta1.ControlPlaneDeploymentOptions{ + PodTemplateSpec: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "controller", + ReadinessProbe: &corev1.Probe{ + InitialDelaySeconds: 1, + PeriodSeconds: 1, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("32Mi"), + }, + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("200m"), + corev1.ResourceMemory: resource.MustParse("256Mi"), + }, + }, + Env: []corev1.EnvVar{ + { + Name: "CONTROLLER_LOG_LEVEL", + Value: "debug", + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + require.NoError(t, clients.MgrClient.Create(ctx, &gwconf)) + t.Cleanup(func() { + require.NoError(t, clients.MgrClient.Delete(ctx, &gwconf)) + }) + gwc := &gatewayv1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ - Name: uuid.NewString(), + GenerateName: "kgo-gwclass-conformance-", }, Spec: gatewayv1.GatewayClassSpec{ ControllerName: gatewayv1.GatewayController(vars.ControllerName()), + ParametersRef: &gatewayv1.ParametersReference{ + Group: "gateway-operator.konghq.com", + Kind: "GatewayConfiguration", + Name: gwconf.Name, + Namespace: lo.ToPtr(gwtypes.Namespace("default")), + }, }, } require.NoError(t, clients.MgrClient.Create(ctx, gwc)) - defer func() { + t.Cleanup(func() { require.NoError(t, clients.MgrClient.Delete(ctx, gwc)) - }() + }) // There are no explicit conformance tests for GatewayClass, but we can // still run the conformance test suite setup to ensure that the