From 7c90169c72078f580934b152a904501dabd72dc5 Mon Sep 17 00:00:00 2001 From: Jakub Warczarek Date: Fri, 17 May 2024 21:26:31 +0200 Subject: [PATCH] fix(conformance): fix panic for `make test.conformance` (#265) --- controller/gateway/controller.go | 2 +- pkg/utils/test/clients.go | 5 +++++ test/conformance/conformance_test.go | 13 ++++--------- test/conformance/suite_test.go | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/controller/gateway/controller.go b/controller/gateway/controller.go index 6078bbb6b..c964564a9 100644 --- a/controller/gateway/controller.go +++ b/controller/gateway/controller.go @@ -172,7 +172,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } // If the Gateway is not accepted, do not move on in the reconciliation logic. if acceptedCondition.Status == metav1.ConditionFalse { - // TODO: clean up Dataplane and Controlplane https://github.com/Kong/gateway-operator/issues/1511 + // TODO: clean up Dataplane and Controlplane https://github.com/Kong/gateway-operator/issues/126 return ctrl.Result{}, nil } diff --git a/pkg/utils/test/clients.go b/pkg/utils/test/clients.go index 8f10871dd..8e364c9ff 100644 --- a/pkg/utils/test/clients.go +++ b/pkg/utils/test/clients.go @@ -2,6 +2,7 @@ package test import ( "github.com/kong/kubernetes-testing-framework/pkg/environments" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" kubernetesclient "k8s.io/client-go/kubernetes" ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" @@ -40,6 +41,10 @@ func NewK8sClients(env environments.Environment) (K8sClients, error) { if err != nil { return clients, err } + + if err := apiextensionsv1.AddToScheme(clients.MgrClient.Scheme()); err != nil { + return clients, err + } if err := gatewayv1.Install(clients.MgrClient.Scheme()); err != nil { return clients, err } diff --git a/test/conformance/conformance_test.go b/test/conformance/conformance_test.go index 9b8e18943..47fb6fe25 100644 --- a/test/conformance/conformance_test.go +++ b/test/conformance/conformance_test.go @@ -1,7 +1,6 @@ package conformance import ( - "flag" "fmt" "os" "path" @@ -15,6 +14,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" 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" @@ -32,11 +32,6 @@ var skippedTests = []string{ tests.HTTPRouteHeaderMatching.ShortName, } -var ( - shouldCleanup = flag.Bool("cleanup", true, "indicates whether or not the base test resources such as Gateways should be cleaned up after the run.") - showDebug = flag.Bool("debug", false, "indicates whether to execute the conformance tests in debug mode.") -) - func TestGatewayConformance(t *testing.T) { t.Parallel() @@ -64,8 +59,8 @@ func TestGatewayConformance(t *testing.T) { suite.ConformanceOptions{ Client: clients.MgrClient, GatewayClassName: gwc.Name, - Debug: *showDebug, - CleanupBaseResources: *shouldCleanup, + Debug: *flags.ShowDebug, + CleanupBaseResources: *flags.CleanupBaseResources, BaseManifests: conformanceTestsBaseManifests, SkipTests: skippedTests, ConformanceProfiles: sets.New( @@ -85,7 +80,7 @@ func TestGatewayConformance(t *testing.T) { require.NoError(t, err) t.Log("starting the gateway conformance test suite") - cSuite.Setup(t, nil) + 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.: diff --git a/test/conformance/suite_test.go b/test/conformance/suite_test.go index ec11f9b34..864b9b54e 100644 --- a/test/conformance/suite_test.go +++ b/test/conformance/suite_test.go @@ -15,6 +15,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/gateway-api/conformance/utils/flags" gwapiv1 "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/typed/apis/v1" "github.com/kong/gateway-operator/config" @@ -126,7 +127,7 @@ func TestMain(m *testing.M) { // for the operator to handle Gateway finalizers. // If we don't do it then we'll be left with Gateways that have a deleted // timestamp and finalizers set but no operator running which could handle those. - if *shouldCleanup { + if *flags.CleanupBaseResources { exitOnErr(waitForConformanceGatewaysToCleanup(ctx, clients.GatewayClient.GatewayV1())) }