Skip to content

Commit 0edc141

Browse files
committed
Adding all changes for environments
1 parent 6de39e9 commit 0edc141

File tree

5 files changed

+23
-107
lines changed

5 files changed

+23
-107
lines changed

src/agentex/lib/cli/commands/agents.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ def deploy(
255255
repository: str | None = typer.Option(
256256
None, help="Override the repository for deployment"
257257
),
258-
override_file: str | None = typer.Option(
259-
None, help="Path to override configuration file"
260-
),
261258
interactive: bool = typer.Option(
262259
True, "--interactive/--no-interactive", help="Enable interactive prompts"
263260
),
@@ -307,16 +304,6 @@ def deploy(
307304
else:
308305
raise DeploymentError(f"No namespace found in environments.yaml for environment: {environment}, and not passed in as --namespace")
309306

310-
# Validate override file exists if provided
311-
if override_file:
312-
override_path = Path(override_file)
313-
if not override_path.exists():
314-
console.print(
315-
f"[red]Error:[/red] Override file not found: {override_file}"
316-
)
317-
raise typer.Exit(1)
318-
319-
320307
# Confirm deployment (only in interactive mode)
321308
console.print("\n[bold]Deployment Summary:[/bold]")
322309
console.print(f" Manifest: {manifest}")
@@ -325,8 +312,6 @@ def deploy(
325312
console.print(f" Namespace: {namespace}")
326313
if tag:
327314
console.print(f" Image Tag: {tag}")
328-
if override_file:
329-
console.print(f" Override File: {override_file}")
330315

331316
if interactive:
332317
proceed = questionary.confirm("Proceed with deployment?").ask()
@@ -355,7 +340,6 @@ def deploy(
355340
cluster_name=cluster,
356341
namespace=namespace,
357342
deploy_overrides=deploy_overrides,
358-
override_file_path=override_file,
359343
environment_name=environment,
360344
)
361345

src/agentex/lib/cli/handlers/deploy_handlers.py

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from agentex.lib.environment_variables import EnvVarKeys
1616
from agentex.lib.sdk.config.agent_config import AgentConfig
1717
from agentex.lib.sdk.config.agent_manifest import AgentManifest
18-
from agentex.lib.sdk.config.deployment_config import ClusterConfig
18+
1919
from agentex.lib.utils.logging import make_logger
2020

2121
logger = 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

9980
def 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
11798
def 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)

src/agentex/lib/cli/templates/default/environments.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ environments:
4343
user_id: # TODO: Fill in
4444
account_id: # TODO: Fill in
4545
helm_overrides:
46-
replicas: 2
46+
replicaCount: 2
4747
resources:
4848
requests:
4949
cpu: "500m"

src/agentex/lib/cli/templates/sync/environments.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ environments:
4242
user_id: # TODO: Fill in
4343
account_id: # TODO: Fill in
4444
helm_overrides:
45-
replicas: 2
45+
replicaCount: 2
4646
resources:
4747
requests:
4848
cpu: "500m"

src/agentex/lib/cli/templates/temporal/environments.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ environments:
4444
account_id: # TODO: Fill in
4545
helm_overrides:
4646
# This is used to override the global helm values.yaml file in the agentex-agent helm charts
47-
replicas: 2
47+
replicaCount: 2
4848
resources:
4949
requests:
5050
cpu: "500m"
@@ -54,7 +54,7 @@ environments:
5454
memory: "2Gi"
5555
temporal:
5656
enabled: true
57-
replicas: 2
57+
replicaCount: 2
5858
resources:
5959
requests:
6060
cpu: "500m"

0 commit comments

Comments
 (0)