Skip to content

Commit 6de39e9

Browse files
committed
Adding changes to be able to init the new environments.yaml file on init
1 parent 0fc5306 commit 6de39e9

File tree

14 files changed

+202
-234
lines changed

14 files changed

+202
-234
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,17 @@ def deploy(
295295
console.print(f"[red]Error:[/red] Failed to load environment config: {e}")
296296
raise typer.Exit(1)
297297

298+
# Load manifest for credential validation
299+
manifest_obj = AgentManifest.from_yaml(str(manifest_path))
300+
298301
# Use namespace from environment config if not overridden
299302
if not namespace:
300-
namespace = agent_env_config.kubernetes.namespace
301-
console.print(f"[blue]ℹ[/blue] Using namespace from environments.yaml: {namespace}")
303+
namespace_from_config = agent_env_config.kubernetes.namespace if agent_env_config.kubernetes else None
304+
if namespace_from_config:
305+
console.print(f"[blue]ℹ[/blue] Using namespace from environments.yaml: {namespace_from_config}")
306+
namespace = namespace_from_config
307+
else:
308+
raise DeploymentError(f"No namespace found in environments.yaml for environment: {environment}, and not passed in as --namespace")
302309

303310
# Validate override file exists if provided
304311
if override_file:
@@ -309,8 +316,6 @@ def deploy(
309316
)
310317
raise typer.Exit(1)
311318

312-
# Load manifest for credential validation
313-
manifest_obj = AgentManifest.from_yaml(str(manifest_path))
314319

315320
# Confirm deployment (only in interactive mode)
316321
console.print("\n[bold]Deployment Summary:[/bold]")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def create_project_structure(
6565
".dockerignore.j2": ".dockerignore",
6666
"manifest.yaml.j2": "manifest.yaml",
6767
"README.md.j2": "README.md",
68+
"environments.yaml.j2": "environments.yaml",
6869
}
6970

7071
# Add package management file based on uv choice

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rich.console import Console
1010

1111
from agentex.lib.cli.utils.exceptions import DeploymentError, HelmError
12+
from agentex.lib.sdk.config.environment_config import AgentEnvironmentConfig
1213
from agentex.lib.cli.utils.kubectl_utils import check_and_switch_cluster_context
1314
from agentex.lib.cli.utils.path_utils import calculate_docker_acp_module, PathResolutionError
1415
from agentex.lib.environment_variables import EnvVarKeys
@@ -115,7 +116,7 @@ def add_acp_command_to_helm_values(helm_values: dict[str, Any], manifest: AgentM
115116

116117
def merge_deployment_configs(
117118
manifest: AgentManifest,
118-
agent_env_config,
119+
agent_env_config: AgentEnvironmentConfig | None,
119120
cluster_config: ClusterConfig | None,
120121
deploy_overrides: InputDeployOverrides,
121122
manifest_path: str,
@@ -193,12 +194,7 @@ def merge_deployment_configs(
193194
if agent_config.env:
194195
all_env_vars.update(agent_config.env)
195196

196-
# Add auth principal env var if environment config is set
197-
if agent_env_config and agent_env_config.auth:
198-
from agentex.lib.cli.utils.auth_utils import _encode_principal_context_from_env_config
199-
encoded_principal = _encode_principal_context_from_env_config(agent_env_config.auth)
200-
if encoded_principal:
201-
all_env_vars[EnvVarKeys.AUTH_PRINCIPAL_B64.value] = encoded_principal
197+
202198

203199
# Handle credentials and check for conflicts
204200
if agent_config.credentials:
@@ -282,11 +278,22 @@ def merge_deployment_configs(
282278

283279
# Apply agent environment configuration overrides
284280
if agent_env_config:
281+
# Add auth principal env var if environment config is set
282+
if agent_env_config.auth:
283+
from agentex.lib.cli.utils.auth_utils import _encode_principal_context_from_env_config
284+
encoded_principal = _encode_principal_context_from_env_config(agent_env_config.auth)
285+
logger.info(f"Encoding auth principal from {agent_env_config.auth}")
286+
if encoded_principal:
287+
all_env_vars[EnvVarKeys.AUTH_PRINCIPAL_B64.value] = encoded_principal
288+
else:
289+
raise DeploymentError(f"Auth principal unable to be encoded for agent_env_config: {agent_env_config}")
290+
285291
if agent_env_config.helm_overrides:
286292
_deep_merge(helm_values, agent_env_config.helm_overrides)
287293

288294
# Set final environment variables
289295
if all_env_vars:
296+
# WORRY: That this will override env vars set in the environments.yaml file
290297
helm_values["env"] = convert_env_vars_dict_to_list(all_env_vars)
291298

292299
if secret_env_vars:

src/agentex/lib/cli/templates/default/deploy/example.yaml.j2

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Agent Environment Configuration
2+
# ------------------------------
3+
# This file defines environment-specific settings for your agent.
4+
# This DIFFERS from the manifest.yaml file in that it is used to program things that are ONLY per environment.
5+
6+
# ********** EXAMPLE **********
7+
# schema_version: "v1" # This is used to validate the file structure and is not used by the agentex CLI
8+
# environments:
9+
# dev:
10+
# auth:
11+
# principal:
12+
# user_id: "1234567890"
13+
# user_name: "John Doe"
14+
# user_email: "[email protected]"
15+
# user_role: "admin"
16+
# user_permissions: "read, write, delete"
17+
# helm_overrides: # This is used to override the global helm values.yaml file in the agentex-agent helm charts
18+
# replicas: 3
19+
# resources:
20+
# requests:
21+
# cpu: "1000m"
22+
# memory: "2Gi"
23+
# limits:
24+
# cpu: "2000m"
25+
# memory: "4Gi"
26+
# env:
27+
# - name: LOG_LEVEL
28+
# value: "DEBUG"
29+
# - name: ENVIRONMENT
30+
# value: "staging"
31+
#
32+
# kubernetes:
33+
# # OPTIONAL - Otherwise it will be derived from separately. However, this can be used to override the derived
34+
# # namespace and deploy it with in the same namespace that already exists for a separate agent.
35+
# namespace: "team-{{agent_name}}"
36+
# ********** END EXAMPLE **********
37+
38+
schema_version: "v1" # This is used to validate the file structure and is not used by the agentex CLI
39+
environments:
40+
dev:
41+
auth:
42+
principal:
43+
user_id: # TODO: Fill in
44+
account_id: # TODO: Fill in
45+
helm_overrides:
46+
replicas: 2
47+
resources:
48+
requests:
49+
cpu: "500m"
50+
memory: "1Gi"
51+
limits:
52+
cpu: "1000m"
53+
memory: "2Gi"
54+
temporal:
55+
enabled: false
56+
57+
Binary file not shown.

src/agentex/lib/cli/templates/deploy/example.yaml.j2

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/agentex/lib/cli/templates/sync/deploy/example.yaml.j2

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Agent Environment Configuration
2+
# ------------------------------
3+
# This file defines environment-specific settings for your agent.
4+
# This DIFFERS from the manifest.yaml file in that it is used to program things that are ONLY per environment.
5+
6+
# ********** EXAMPLE **********
7+
# schema_version: "v1" # This is used to validate the file structure and is not used by the agentex CLI
8+
# environments:
9+
# dev:
10+
# auth:
11+
# principal:
12+
# user_id: "1234567890"
13+
# user_name: "John Doe"
14+
# user_email: "[email protected]"
15+
# user_role: "admin"
16+
# user_permissions: "read, write, delete"
17+
# helm_overrides: # This is used to override the global helm values.yaml file in the agentex-agent helm charts
18+
# replicas: 3
19+
# resources:
20+
# requests:
21+
# cpu: "1000m"
22+
# memory: "2Gi"
23+
# limits:
24+
# cpu: "2000m"
25+
# memory: "4Gi"
26+
# env:
27+
# - name: LOG_LEVEL
28+
# value: "DEBUG"
29+
# - name: ENVIRONMENT
30+
# value: "staging"
31+
# kubernetes:
32+
# # OPTIONAL - Otherwise it will be derived from separately. However, this can be used to override the derived
33+
# # namespace and deploy it with in the same namespace that already exists for a separate agent.
34+
# namespace: "team-{{agent_name}}"
35+
# ********** END EXAMPLE **********
36+
37+
schema_version: "v1" # This is used to validate the file structure and is not used by the agentex CLI
38+
environments:
39+
dev:
40+
auth:
41+
principal:
42+
user_id: # TODO: Fill in
43+
account_id: # TODO: Fill in
44+
helm_overrides:
45+
replicas: 2
46+
resources:
47+
requests:
48+
cpu: "500m"
49+
memory: "1Gi"
50+
limits:
51+
cpu: "1000m"
52+
memory: "2Gi"
53+

0 commit comments

Comments
 (0)