1515from agentex .lib .environment_variables import EnvVarKeys
1616from agentex .lib .sdk .config .agent_config import AgentConfig
1717from agentex .lib .sdk .config .agent_manifest import AgentManifest
18- from agentex . lib . sdk . config . deployment_config import ClusterConfig
18+
1919from agentex .lib .utils .logging import make_logger
2020
2121logger = make_logger (__name__ )
@@ -76,25 +76,6 @@ def add_helm_repo() -> None:
7676 raise HelmError (f"Failed to add helm repository: { e } " ) from e
7777
7878
79- def load_override_config (override_file_path : str | None = None ) -> ClusterConfig | None :
80- """Load override configuration from specified file path"""
81- if not override_file_path :
82- return None
83-
84- override_path = Path (override_file_path )
85- if not override_path .exists ():
86- raise DeploymentError (f"Override file not found: { override_file_path } " )
87-
88- try :
89- with open (override_path ) as f :
90- config_data = yaml .safe_load (f )
91- return ClusterConfig (** config_data ) if config_data else None
92- except Exception as e :
93- raise DeploymentError (
94- f"Failed to load override config from { override_file_path } : { e } "
95- ) from e
96-
97-
9879
9980def convert_env_vars_dict_to_list (env_vars : dict [str , str ]) -> list [dict [str , str ]]:
10081 """Convert a dictionary of environment variables to a list of dictionaries"""
@@ -117,13 +98,12 @@ def add_acp_command_to_helm_values(helm_values: dict[str, Any], manifest: AgentM
11798def merge_deployment_configs (
11899 manifest : AgentManifest ,
119100 agent_env_config : AgentEnvironmentConfig | None ,
120- cluster_config : ClusterConfig | None ,
121101 deploy_overrides : InputDeployOverrides ,
122102 manifest_path : str ,
123103) -> dict [str , Any ]:
124104 agent_config : AgentConfig = manifest .agent
125105
126- """Merge global deployment config with cluster -specific overrides into helm values"""
106+ """Merge global deployment config with environment -specific overrides into helm values"""
127107 if not manifest .deployment :
128108 raise DeploymentError ("No deployment configuration found in manifest" )
129109
@@ -186,13 +166,25 @@ def merge_deployment_configs(
186166 "taskQueue" : temporal_config .queue_name ,
187167 }
188168
189- # Collect all environment variables with conflict detection
169+ # Collect all environment variables with proper precedence
170+ # Priority: manifest -> environments.yaml -> secrets (highest)
190171 all_env_vars : dict [str , str ] = {}
191172 secret_env_vars : list [dict [str , str ]] = []
192173
193- # Start with agent_config env vars
174+ # Start with agent_config env vars from manifest
194175 if agent_config .env :
195176 all_env_vars .update (agent_config .env )
177+
178+ # Override with environment config env vars if they exist
179+ if agent_env_config and agent_env_config .helm_overrides and "env" in agent_env_config .helm_overrides :
180+ env_overrides = agent_env_config .helm_overrides ["env" ]
181+ if isinstance (env_overrides , list ):
182+ # Convert list format to dict for easier merging
183+ env_override_dict : dict [str , str ] = {}
184+ for env_var in env_overrides :
185+ if isinstance (env_var , dict ) and "name" in env_var and "value" in env_var :
186+ env_override_dict [str (env_var ["name" ])] = str (env_var ["value" ])
187+ all_env_vars .update (env_override_dict )
196188
197189
198190
@@ -226,56 +218,6 @@ def merge_deployment_configs(
226218 }
227219 )
228220
229- # Apply cluster-specific overrides
230- if cluster_config :
231- if cluster_config .image :
232- if cluster_config .image .repository :
233- helm_values ["global" ]["image" ]["repository" ] = (
234- cluster_config .image .repository
235- )
236- if cluster_config .image .tag :
237- helm_values ["global" ]["image" ]["tag" ] = cluster_config .image .tag
238-
239- if cluster_config .replicaCount is not None :
240- helm_values ["replicaCount" ] = cluster_config .replicaCount
241-
242- if cluster_config .resources :
243- if cluster_config .resources .requests :
244- helm_values ["resources" ]["requests" ].update (
245- {
246- "cpu" : cluster_config .resources .requests .cpu ,
247- "memory" : cluster_config .resources .requests .memory ,
248- }
249- )
250- if cluster_config .resources .limits :
251- helm_values ["resources" ]["limits" ].update (
252- {
253- "cpu" : cluster_config .resources .limits .cpu ,
254- "memory" : cluster_config .resources .limits .memory ,
255- }
256- )
257-
258- # Handle cluster env vars with conflict detection
259- if cluster_config .env :
260- # Convert cluster env list to dict for easier conflict detection
261- cluster_env_dict = {env_var ["name" ]: env_var ["value" ] for env_var in cluster_config .env }
262-
263- # Check for conflicts with secret env vars
264- for secret_env_var in secret_env_vars :
265- if secret_env_var ["name" ] in cluster_env_dict :
266- logger .warning (
267- f"Environment variable '{ secret_env_var ['name' ]} ' is defined in both "
268- f"cluster config env and secretEnvVars. The secret value will take precedence."
269- )
270- del cluster_env_dict [secret_env_var ["name" ]]
271-
272- # Update all_env_vars with cluster overrides
273- all_env_vars .update (cluster_env_dict )
274-
275- # Apply additional arbitrary overrides
276- if cluster_config .additional_overrides :
277- _deep_merge (helm_values , cluster_config .additional_overrides )
278-
279221 # Apply agent environment configuration overrides
280222 if agent_env_config :
281223 # Add auth principal env var if environment config is set
@@ -292,8 +234,8 @@ def merge_deployment_configs(
292234 _deep_merge (helm_values , agent_env_config .helm_overrides )
293235
294236 # Set final environment variables
237+ # Environment variable precedence: manifest -> environments.yaml -> secrets (highest)
295238 if all_env_vars :
296- # WORRY: That this will override env vars set in the environments.yaml file
297239 helm_values ["env" ] = convert_env_vars_dict_to_list (all_env_vars )
298240
299241 if secret_env_vars :
@@ -309,7 +251,7 @@ def merge_deployment_configs(
309251 # Handle image pull secrets
310252 if manifest .deployment and manifest .deployment .imagePullSecrets :
311253 pull_secrets = [
312- pull_secret .to_dict ()
254+ pull_secret .model_dump ()
313255 for pull_secret in manifest .deployment .imagePullSecrets
314256 ]
315257 helm_values ["global" ]["imagePullSecrets" ] = pull_secrets
@@ -347,7 +289,6 @@ def deploy_agent(
347289 cluster_name : str ,
348290 namespace : str ,
349291 deploy_overrides : InputDeployOverrides ,
350- override_file_path : str | None = None ,
351292 environment_name : str | None = None ,
352293) -> None :
353294 """Deploy an agent using helm"""
@@ -360,7 +301,6 @@ def deploy_agent(
360301 check_and_switch_cluster_context (cluster_name )
361302
362303 manifest = AgentManifest .from_yaml (file_path = manifest_path )
363- override_config = load_override_config (override_file_path )
364304
365305 # Load agent environment configuration
366306 agent_env_config = None
@@ -373,19 +313,11 @@ def deploy_agent(
373313 else :
374314 console .print (f"[yellow]⚠[/yellow] No environments.yaml found, skipping environment-specific config" )
375315
376- # Provide feedback about override configuration
377- if override_config :
378- console .print (f"[green]✓[/green] Using override config: { override_file_path } " )
379- else :
380- console .print (
381- "[yellow]ℹ[/yellow] No override config specified, using global defaults"
382- )
383-
384316 # Add helm repository/update
385317 add_helm_repo ()
386318
387319 # Merge configurations
388- helm_values = merge_deployment_configs (manifest , agent_env_config , override_config , deploy_overrides , manifest_path )
320+ helm_values = merge_deployment_configs (manifest , agent_env_config , deploy_overrides , manifest_path )
389321
390322 # Create values file
391323 values_file = create_helm_values_file (helm_values )
0 commit comments