Skip to content

feat(conformance): Use CRD annotation to populate the ConformanceReport GatewayAPIInferenceExtensionVersion #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
38 changes: 30 additions & 8 deletions conformance/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ 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/manifests/manifests.yaml"

opts := confsuite.ConformanceOptions{
Expand Down Expand Up @@ -189,7 +185,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 @@ -232,19 +227,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)
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 @@ -284,6 +288,24 @@ func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSui
ensureGatewayAvailableAndReady(t, suite.Client, opts, 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