55"""
66
77import os
8+ import re
89import subprocess
910import tempfile
1011from typing import Optional
@@ -234,6 +235,24 @@ def remove_configmap_backup(backup_key: str) -> None:
234235 print (f"ConfigMap backup { backup_key } removed from memory" )
235236
236237
238+ def _apply_inference_overrides (content : str ) -> str :
239+ """Override inference defaults from E2E env vars if set.
240+
241+ When E2E_DEFAULT_MODEL_OVERRIDE or E2E_DEFAULT_PROVIDER_OVERRIDE are set,
242+ patch the YAML content so every config swap uses the correct model/provider
243+ for the current environment (e.g. vLLM instead of OpenAI in RHOAI Prow).
244+ """
245+ model = os .getenv ("E2E_DEFAULT_MODEL_OVERRIDE" )
246+ provider = os .getenv ("E2E_DEFAULT_PROVIDER_OVERRIDE" )
247+ if not model and not provider :
248+ return content
249+ if model :
250+ content = re .sub (r"(default_model:\s*).*" , rf"\g<1>{ model } " , content )
251+ if provider :
252+ content = re .sub (r"(default_provider:\s*).*" , rf"\g<1>{ provider } " , content )
253+ return content
254+
255+
237256def _recreate_configmap (
238257 configmap_name : str ,
239258 source_file : str ,
@@ -270,7 +289,7 @@ def update_config_configmap(
270289 """
271290 # Check if source is a backup key (restore from memory)
272291 if source in _configmap_backups :
273- config_content = _configmap_backups [source ]
292+ config_content = _apply_inference_overrides ( _configmap_backups [source ])
274293 print (f"Restoring ConfigMap { configmap_name } from memory backup..." )
275294
276295 # Write content to temp file (oc create configmap requires a file)
@@ -289,12 +308,28 @@ def update_config_configmap(
289308 os .remove (temp_path )
290309 return
291310
292- # Otherwise, source is a file path
311+ # Otherwise, source is a file path — apply inference overrides if needed
293312 print (f"Updating ConfigMap { configmap_name } with config from { source } ..." )
294313
314+ source_to_apply = source
315+ temp_path = None
295316 try :
296- _recreate_configmap (configmap_name , source , configmap_key )
317+ with open (source ) as f :
318+ patched = _apply_inference_overrides (f .read ())
319+ with open (source ) as f :
320+ original = f .read ()
321+ if patched != original :
322+ tmp = tempfile .NamedTemporaryFile (mode = "w" , suffix = ".yaml" , delete = False )
323+ tmp .write (patched )
324+ tmp .close ()
325+ source_to_apply = tmp .name
326+ temp_path = tmp .name
327+
328+ _recreate_configmap (configmap_name , source_to_apply , configmap_key )
297329 print (f"ConfigMap { configmap_name } updated successfully" )
298330 except subprocess .CalledProcessError as e :
299331 print (f"Failed to update ConfigMap: { e } " )
300332 raise
333+ finally :
334+ if temp_path and os .path .exists (temp_path ):
335+ os .remove (temp_path )
0 commit comments