Skip to content

Commit 7e9fa29

Browse files
committed
Use CRD annotation to get the inferencePool BundleVersion for ConformanceReport.
1 parent 7c84b2f commit 7e9fa29

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

conformance/conformance.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ func DefaultOptions(t *testing.T) confsuite.ConformanceOptions {
134134
*confflags.ImplementationContact,
135135
)
136136

137-
// Inference Extension Specific Report Fields
138-
inferenceExtensionVersion := "v0.3.0"
139-
_ = inferenceExtensionVersion // Avoid unused variable error until implemented
140-
141137
baseManifestsValue := "resources/base.yaml"
142-
143138
opts := confsuite.ConformanceOptions{
144139
Client: c,
145140
ClientOptions: clientOptions,
@@ -166,7 +161,6 @@ func DefaultOptions(t *testing.T) confsuite.ConformanceOptions {
166161
// TODO: Add the inference extension specific fields to ConformanceOptions struct if needed,
167162
// or handle them during report generation.
168163
// GatewayAPIInferenceExtensionChannel: inferenceExtensionChannel,
169-
// GatewayAPIInferenceExtensionVersion: inferenceExtensionVersion,
170164
}
171165

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

206+
installedCRDs := &apiextensionsv1.CustomResourceDefinitionList{}
207+
err = opts.Client.List(context.TODO(), installedCRDs)
208+
require.NoError(t, err, "error getting installedCRDs")
209+
apiVersion, err := getGatewayInferenceExtentionVersion(installedCRDs.Items)
210+
if err != nil {
211+
if opts.AllowCRDsMismatch {
212+
apiVersion = "UNDEFINED"
213+
} else {
214+
require.NoError(t, err, "error getting the gateway ineference extension version")
215+
}
216+
}
212217
SetupConformanceTestSuite(t, cSuite, opts, tests.ConformanceTests)
213-
214218
t.Log("Running Inference Extension conformance tests against all registered tests")
215219
err = cSuite.Run(t, tests.ConformanceTests)
216220
require.NoError(t, err, "error running conformance tests")
217221

218-
// Generate and write the report if requested.
219222
if opts.ReportOutputPath != "" {
220223
t.Log("Generating Inference Extension conformance report")
221224
report, err := cSuite.Report() // Use the existing report generation logic.
222225
require.NoError(t, err, "error generating conformance report")
223226
inferenceReport := GatewayAPIInferenceExtensionConformanceReport{
224-
GatewayAPIInferenceExtensionVersion: version.BundleVersion,
227+
GatewayAPIInferenceExtensionVersion: apiVersion,
225228
ConformanceReport: *report,
226229
}
227230
err = inferenceReport.WriteReport(t.Logf, opts.ReportOutputPath)
@@ -261,6 +264,24 @@ func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSui
261264
ensureGatewayAvailableAndReady(t, suite.Client, opts, resources.SecondaryGatewayNN)
262265
}
263266

267+
func getGatewayInferenceExtentionVersion(crds []apiextensionsv1.CustomResourceDefinition) (string, error) {
268+
var inferenceVersion string
269+
for _, crd := range crds {
270+
v, okv := crd.Annotations[version.BundleVersionAnnotation]
271+
if !okv {
272+
continue
273+
}
274+
if inferenceVersion != "" && v != inferenceVersion {
275+
return "", errors.New("multiple gateway api inference extension CRDs versions detected")
276+
}
277+
inferenceVersion = v
278+
}
279+
if inferenceVersion == "" {
280+
return "", errors.New("no gateway api inference extension CRDs with the proper annotations found in the cluster")
281+
}
282+
return inferenceVersion, nil
283+
}
284+
264285
// ensureGatewayAvailableAndReady polls for the specified Gateway to exist and become ready
265286
// with an address and programmed condition.
266287
func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts confsuite.ConformanceOptions, gatewayNN types.NamespacedName) {

0 commit comments

Comments
 (0)