Skip to content
Merged
Changes from 1 commit
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
39 changes: 30 additions & 9 deletions conformance/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ func DefaultOptions(t *testing.T) confsuite.ConformanceOptions {
*confflags.ImplementationContact,
)

// Inference Extension Specific Report Fields
inferenceExtensionVersion := "v0.3.0"
_ = inferenceExtensionVersion // Avoid unused variable error until implemented

baseManifestsValue := "resources/base.yaml"

opts := confsuite.ConformanceOptions{
Client: c,
ClientOptions: clientOptions,
Expand All @@ -166,7 +161,6 @@ func DefaultOptions(t *testing.T) confsuite.ConformanceOptions {
// TODO: Add the inference extension specific fields to ConformanceOptions struct if needed,
// or handle them during report generation.
// GatewayAPIInferenceExtensionChannel: inferenceExtensionChannel,
// GatewayAPIInferenceExtensionVersion: inferenceExtensionVersion,
}

// Populate SupportedFeatures based on the GatewayLayerProfile.
Expand Down Expand Up @@ -209,19 +203,28 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
cSuite, err := confsuite.NewConformanceTestSuite(opts)
require.NoError(t, err, "error initializing conformance suite")

installedCRDs := &apiextensionsv1.CustomResourceDefinitionList{}
err = opts.Client.List(context.TODO(), installedCRDs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the use of context in conformance is not aligned with best practices.
I was hoping to see context created one time in "main" (e.g., in the entry point), and then ctx is propagated in the function calls (usually as first arg).
I've never ran the conformance test suite myself, but if it's a long running process (more than few minutes), it may make sense to use context with signal handling (listening to SIGTERM, SIGKILL).
see example in our main file where we use SetupSignalHandler():

if err := runner.NewRunner().Run(ctrl.SetupSignalHandler()); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good call! I've replaced it by creating a context.Background() at the start of the test run and propagating it down. The conformance tests is executed by go test. Each test function serves as its own entry point. The overall process termination is managed by the go test --timeout flag, so setting up a custom signal handler here isn't necessary as it would be in a long-running service.

Ref:

func TestConformance(t *testing.T) {
is the entryPoint for conformance tests which is run by go test

require.NoError(t, err, "error getting installedCRDs")
apiVersion, err := getGatewayInferenceExtentionVersion(installedCRDs.Items)
if err != nil {
if opts.AllowCRDsMismatch {
apiVersion = "UNDEFINED"
} else {
require.NoError(t, err, "error getting the gateway ineference extension version")
}
}
SetupConformanceTestSuite(t, cSuite, opts, tests.ConformanceTests)

t.Log("Running Inference Extension conformance tests against all registered tests")
err = cSuite.Run(t, tests.ConformanceTests)
require.NoError(t, err, "error running conformance tests")

// Generate and write the report if requested.
if opts.ReportOutputPath != "" {
t.Log("Generating Inference Extension conformance report")
report, err := cSuite.Report() // Use the existing report generation logic.
require.NoError(t, err, "error generating conformance report")
inferenceReport := GatewayAPIInferenceExtensionConformanceReport{
GatewayAPIInferenceExtensionVersion: version.BundleVersion,
GatewayAPIInferenceExtensionVersion: apiVersion,
ConformanceReport: *report,
}
err = inferenceReport.WriteReport(t.Logf, opts.ReportOutputPath)
Expand Down Expand Up @@ -261,6 +264,24 @@ func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSui
ensureGatewayAvailableAndReady(t, suite.Client, opts, resources.SecondaryGatewayNN)
}

func getGatewayInferenceExtentionVersion(crds []apiextensionsv1.CustomResourceDefinition) (string, error) {
var inferenceVersion string
for _, crd := range crds {
v, okv := crd.Annotations[version.BundleVersionAnnotation]
if !okv {
continue
}
if inferenceVersion != "" && v != inferenceVersion {
return "", errors.New("multiple gateway api inference extension CRDs versions detected")
}
inferenceVersion = v
}
if inferenceVersion == "" {
return "", errors.New("no gateway api inference extension CRDs with the proper annotations found in the cluster")
}
return inferenceVersion, nil
}

// ensureGatewayAvailableAndReady polls for the specified Gateway to exist and become ready
// with an address and programmed condition.
func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts confsuite.ConformanceOptions, gatewayNN types.NamespacedName) {
Expand Down