Skip to content

Commit f8b2e19

Browse files
authored
fix conformance setup issue by separating the dependency on gateway-api. (#1060)
1 parent 83260cc commit f8b2e19

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

conformance/conformance.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"io/fs"
2626
"os"
27+
"slices"
2728
"testing"
2829

2930
"github.com/stretchr/testify/require"
@@ -48,6 +49,7 @@ import (
4849
confflags "sigs.k8s.io/gateway-api/conformance/utils/flags"
4950
apikubernetes "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
5051
confsuite "sigs.k8s.io/gateway-api/conformance/utils/suite"
52+
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
5153
"sigs.k8s.io/gateway-api/pkg/features"
5254

5355
// Import the test definitions package to access the ConformanceTests slice
@@ -65,10 +67,16 @@ import (
6567
inferenceconfig "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/config"
6668
)
6769

68-
// Constants for the shared Gateway
6970
const (
70-
SharedGatewayName = "conformance-primary-gateway" // Name of the Gateway in manifests.yaml
71-
SharedGatewayNamespace = "gateway-conformance-infra" // Namespace of the Gateway
71+
infraNameSpace = "gateway-conformance-infra"
72+
appBackendNameSpace = "gateway-conformance-app-backend"
73+
primaryGatewayName = "conformance-primary-gateway"
74+
secondaryGatewayName = "conformance-secondary-gateway"
75+
)
76+
77+
var (
78+
primaryGatewayNN = types.NamespacedName{Name: primaryGatewayName, Namespace: infraNameSpace}
79+
secondaryGatewayNN = types.NamespacedName{Name: secondaryGatewayName, Namespace: infraNameSpace}
7280
)
7381

7482
// GatewayLayerProfileName defines the name for the conformance profile that tests
@@ -225,12 +233,8 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
225233
cSuite, err := confsuite.NewConformanceTestSuite(opts)
226234
require.NoError(t, err, "error initializing conformance suite")
227235

228-
cSuite.Setup(t, tests.ConformanceTests)
236+
SetupConformanceTestSuite(t, cSuite, opts, tests.ConformanceTests)
229237

230-
sharedGwNN := types.NamespacedName{Name: SharedGatewayName, Namespace: SharedGatewayNamespace}
231-
232-
// Validate Gateway setup.
233-
ensureGatewayAvailableAndReady(t, cSuite.Client, opts, sharedGwNN)
234238
t.Log("Running Inference Extension conformance tests against all registered tests")
235239
err = cSuite.Run(t, tests.ConformanceTests)
236240
require.NoError(t, err, "error running conformance tests")
@@ -251,6 +255,38 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
251255
}
252256
}
253257

258+
func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSuite, opts confsuite.ConformanceOptions, tests []confsuite.ConformanceTest) {
259+
suite.Applier.ManifestFS = suite.ManifestFS
260+
if suite.RunTest != "" {
261+
idx := slices.IndexFunc(tests, func(t confsuite.ConformanceTest) bool {
262+
return t.ShortName == suite.RunTest
263+
})
264+
265+
if idx == -1 {
266+
require.FailNow(t, fmt.Sprintf("Test %q does not exist", suite.RunTest))
267+
}
268+
}
269+
270+
tlog.Logf(t, "Test Setup: Ensuring GatewayClass has been accepted")
271+
suite.ControllerName = apikubernetes.GWCMustHaveAcceptedConditionTrue(t, suite.Client, suite.TimeoutConfig, suite.GatewayClassName)
272+
273+
suite.Applier.GatewayClass = suite.GatewayClassName
274+
suite.Applier.ControllerName = suite.ControllerName
275+
276+
tlog.Logf(t, "Test Setup: Applying base manifests")
277+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, suite.BaseManifests, suite.Cleanup)
278+
279+
tlog.Logf(t, "Test Setup: Ensuring Gateways and Pods from base manifests are ready")
280+
namespaces := []string{
281+
infraNameSpace,
282+
appBackendNameSpace,
283+
}
284+
apikubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, namespaces)
285+
286+
ensureGatewayAvailableAndReady(t, suite.Client, opts, primaryGatewayNN)
287+
ensureGatewayAvailableAndReady(t, suite.Client, opts, secondaryGatewayNN)
288+
}
289+
254290
// ensureGatewayAvailableAndReady polls for the specified Gateway to exist and become ready
255291
// with an address and programmed condition.
256292
func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts confsuite.ConformanceOptions, gatewayNN types.NamespacedName) {

0 commit comments

Comments
 (0)