From ac45eecdf05bd6ff06c66ad63301c82fdce51f15 Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Mon, 20 May 2024 13:22:49 +0200 Subject: [PATCH] tests(fix): conformance tests pass --- controller/gateway/controller.go | 2 +- test/conformance/conformance_test.go | 76 +++++++++------------------- test/conformance/suite_test.go | 5 +- 3 files changed, 30 insertions(+), 53 deletions(-) diff --git a/controller/gateway/controller.go b/controller/gateway/controller.go index c964564a9..267f99d99 100644 --- a/controller/gateway/controller.go +++ b/controller/gateway/controller.go @@ -309,7 +309,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, nil // requeue will be triggered by the update of the controlplane status } - // if the controlplane wasnt't ready before this reconciliation loop and now is ready, log this event + // if the controlplane wasn't ready before this reconciliation loop and now is ready, log this event if !k8sutils.IsConditionTrue(ControlPlaneReadyType, oldGwConditionsAware) { log.Debug(logger, "controlplane is ready", gateway) } diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index 47fb6fe25..9523b25f6 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -2,19 +2,17 @@ package conformance import ( "fmt" - "os" "path" "testing" "github.com/google/uuid" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/conformance" conformancev1 "sigs.k8s.io/gateway-api/conformance/apis/v1" "sigs.k8s.io/gateway-api/conformance/tests" - "sigs.k8s.io/gateway-api/conformance/utils/flags" "sigs.k8s.io/gateway-api/conformance/utils/suite" "github.com/kong/gateway-operator/internal/metadata" @@ -30,6 +28,11 @@ var skippedTests = []string{ // httproute tests.HTTPRouteHeaderMatching.ShortName, + tests.HTTPRouteHTTPSListener.ShortName, + tests.HTTPRouteHostnameIntersection.ShortName, + tests.HTTPRouteInvalidBackendRefUnknownKind.ShortName, + tests.HTTPRouteListenerHostnameMatching.ShortName, + tests.HTTPRouteObservedGenerationBump.ShortName, } func TestGatewayConformance(t *testing.T) { @@ -53,56 +56,27 @@ func TestGatewayConformance(t *testing.T) { // still run the conformance test suite setup to ensure that the // GatewayClass gets accepted. t.Log("starting the gateway conformance test suite") - conformanceTestsBaseManifests := fmt.Sprintf("%s/conformance/base/manifests.yaml", testutils.GatewayRawRepoURL) + const reportFileName = "kong-gateway-operator.yaml" // TODO: https://github.com/Kong/gateway-operator/issues/268 - cSuite, err := suite.NewConformanceTestSuite( - suite.ConformanceOptions{ - Client: clients.MgrClient, - GatewayClassName: gwc.Name, - Debug: *flags.ShowDebug, - CleanupBaseResources: *flags.CleanupBaseResources, - BaseManifests: conformanceTestsBaseManifests, - SkipTests: skippedTests, - ConformanceProfiles: sets.New( - suite.GatewayHTTPConformanceProfileName, - ), - Implementation: conformancev1.Implementation{ - Organization: metadata.Organization, - Project: metadata.ProjectName, - URL: metadata.ProjectURL, - Version: metadata.Release, - Contact: []string{ - path.Join(metadata.ProjectURL, "/issues/new/choose"), - }, - }, - }, + opts := conformance.DefaultOptions(t) + opts.ReportOutputPath = "../../" + reportFileName + opts.Client = clients.MgrClient + opts.GatewayClassName = gwc.Name + opts.BaseManifests = fmt.Sprintf("%s/conformance/base/manifests.yaml", testutils.GatewayRawRepoURL) + opts.SkipTests = skippedTests + opts.ConformanceProfiles = sets.New( + suite.GatewayHTTPConformanceProfileName, ) - require.NoError(t, err) + opts.Implementation = conformancev1.Implementation{ + Organization: metadata.Organization, + Project: metadata.ProjectName, + URL: metadata.ProjectURL, + Version: metadata.Release, + Contact: []string{ + path.Join(metadata.ProjectURL, "/issues/new/choose"), + }, + } t.Log("starting the gateway conformance test suite") - cSuite.Setup(t, tests.ConformanceTests) - - // To work with individual tests only, you can disable the normal Run call and construct a slice containing a - // single test only, e.g.: - // - // cSuite.Run(t, []suite.ConformanceTest{tests.GatewayClassObservedGenerationBump}) - // To work with individual tests only, you can disable the normal Run call and construct a slice containing a - // single test only, e.g.: - // - // cSuite.Run(t, []suite.ConformanceTest{tests.HTTPRouteRedirectPortAndScheme}) - require.NoError(t, cSuite.Run(t, tests.ConformanceTests)) - - // In the future we'll likely change the file name as https://github.com/kubernetes-sigs/gateway-api/issues/2740 will be implemented. - // The day it will happen, we'll have to change the .gitignore entry as well. - const reportFileName = "kong-gateway-operator.yaml" - - t.Log("saving the gateway conformance test report to file:", reportFileName) - report, err := cSuite.Report() - require.NoError(t, err) - rawReport, err := yaml.Marshal(report) - require.NoError(t, err) - fmt.Println("INFO: final report") - fmt.Println(string(rawReport)) - // Save report in root of the repository, file name is in .gitignore. - require.NoError(t, os.WriteFile("../../"+reportFileName, rawReport, 0o600)) + conformance.RunConformanceWithOptions(t, opts) } diff --git a/test/conformance/suite_test.go b/test/conformance/suite_test.go index 864b9b54e..8dffb1953 100644 --- a/test/conformance/suite_test.go +++ b/test/conformance/suite_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/kong/kubernetes-testing-framework/pkg/clusters" + "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb" "github.com/kong/kubernetes-testing-framework/pkg/environments" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" @@ -78,7 +79,9 @@ func TestMain(m *testing.M) { // Gateway API conformance tests do not create resources like NetworkPolicy // that would allow e.g. cross namespace traffic. // Related upstream discussion: https://github.com/kubernetes-sigs/gateway-api/discussions/2137 - env, err = testutils.BuildEnvironment(ctx, existingCluster) + env, err = testutils.BuildEnvironment(ctx, existingCluster, func(b *environments.Builder, t clusters.Type) { + b.WithAddons(metallb.New()) + }) exitOnErr(err) fmt.Printf("INFO: waiting for cluster %s and all addons to become ready\n", env.Cluster().Name())