33
44import pytest
55from kubernetes .dynamic import DynamicClient
6+ from kubernetes .dynamic .exceptions import ResourceNotFoundError
67from ocp_resources .job import Job
78
89from tests .model_registry .async_job .constants import (
910 ASYNC_JOB_ANNOTATIONS ,
1011 ASYNC_JOB_LABELS ,
11- ASYNC_UPLOAD_IMAGE ,
1212 ASYNC_UPLOAD_JOB_NAME ,
1313 MODEL_SYNC_CONFIG ,
1414 VOLUME_MOUNTS ,
1515)
1616
1717import shortuuid
1818from pytest import FixtureRequest
19+ from pytest_testconfig import py_config
1920
2021from ocp_resources .namespace import Namespace
2122from ocp_resources .pod import Pod
2526from ocp_resources .service import Service
2627from ocp_resources .service_account import ServiceAccount
2728from ocp_resources .model_registry_modelregistry_opendatahub_io import ModelRegistry
29+ from ocp_resources .config_map import ConfigMap
2830from model_registry .types import RegisteredModel
2931from model_registry import ModelRegistry as ModelRegistryClient
3032
@@ -114,6 +116,39 @@ def oci_secret_for_async_job(
114116 yield secret
115117
116118
119+ @pytest .fixture (scope = "class" )
120+ def async_upload_image (admin_client : DynamicClient ) -> str :
121+ """
122+ Get the async upload image dynamically from the model-registry-operator-parameters ConfigMap.
123+
124+ This fetches the image from the cluster at runtime instead of using a hardcoded value.
125+
126+ Args:
127+ admin_client: Kubernetes client for resource access
128+
129+ Returns:
130+ str: The async upload image URL from the ConfigMap
131+
132+ Raises:
133+ KeyError: If the ConfigMap or the required key doesn't exist
134+ """
135+ config_map = ConfigMap (
136+ client = admin_client ,
137+ name = "model-registry-operator-parameters" ,
138+ namespace = py_config ["applications_namespace" ],
139+ )
140+
141+ if not config_map .exists :
142+ raise ResourceNotFoundError (
143+ f"ConfigMap 'model-registry-operator-parameters' not found in namespace '{ py_config ['applications_namespace' ]} '" # noqa: E501
144+ )
145+
146+ try :
147+ return config_map .instance .data ["IMAGES_JOBS_ASYNC_UPLOAD" ]
148+ except KeyError as e :
149+ raise KeyError (f"Key 'IMAGES_JOBS_ASYNC_UPLOAD' not found in ConfigMap data: { e } " ) from e
150+
151+
117152@pytest .fixture (scope = "class" )
118153def model_sync_async_job (
119154 admin_client : DynamicClient ,
@@ -125,6 +160,7 @@ def model_sync_async_job(
125160 oci_secret_for_async_job : Secret ,
126161 oci_registry_host : str ,
127162 mr_access_role_binding : RoleBinding ,
163+ async_upload_image : str ,
128164 teardown_resources : bool ,
129165) -> Generator [Job , Any , Any ]:
130166 """
@@ -146,6 +182,7 @@ def model_sync_async_job(
146182 oci_secret_for_async_job: Secret containing OCI registry credentials
147183 oci_registry_host: OCI registry hostname
148184 mr_access_role_binding: Role binding for Model Registry access
185+ async_upload_image: Container image URL for async upload job (fetched dynamically)
149186 teardown_resources: Whether to clean up resources after test
150187
151188 Returns:
@@ -210,7 +247,7 @@ def model_sync_async_job(
210247 containers = [
211248 {
212249 "name" : "async-upload" ,
213- "image" : ASYNC_UPLOAD_IMAGE ,
250+ "image" : async_upload_image ,
214251 "volumeMounts" : volume_mounts ,
215252 "env" : environment_variables ,
216253 }
0 commit comments