Skip to content

Commit d24b0b2

Browse files
committed
Adding changes to python
1 parent 0edc141 commit d24b0b2

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
InputDeployOverrides,
2020
deploy_agent,
2121
)
22+
from agentex.lib.sdk.config.validation import (
23+
validate_manifest_and_environments,
24+
EnvironmentsValidationError,
25+
generate_helpful_error_message
26+
)
2227
from agentex.lib.cli.utils.cli_utils import handle_questionary_cancellation
2328
from agentex.lib.cli.utils.kubectl_utils import (
2429
check_and_switch_cluster_context,
@@ -272,24 +277,21 @@ def deploy(
272277
console.print(f"[red]Error:[/red] Manifest file not found: {manifest}")
273278
raise typer.Exit(1)
274279

275-
# Validate environments.yaml exists
276-
environments_file = manifest_path.parent / "environments.yaml"
277-
if not environments_file.exists():
278-
console.print(f"[red]Error:[/red] environments.yaml not found next to {manifest}")
279-
console.print("\n💡 To create one:")
280-
console.print(" agentex agents init-environments")
281-
console.print("\n📋 Why required:")
282-
console.print(" Environment-specific settings (auth, namespace, resources)")
283-
console.print(" must be separated from global manifest for proper isolation.")
284-
raise typer.Exit(1)
285-
286-
# Load and validate environment configuration
280+
# Validate manifest and environments configuration
287281
try:
288-
from agentex.lib.sdk.config.environment_config import AgentEnvironmentsConfig
289-
environments_config = AgentEnvironmentsConfig.from_yaml(str(environments_file))
282+
_, environments_config = validate_manifest_and_environments(
283+
str(manifest_path),
284+
required_environment=environment
285+
)
290286
agent_env_config = environments_config.get_config_for_env(environment)
287+
console.print(f"[green]✓[/green] Environment config validated: {environment}")
288+
289+
except EnvironmentsValidationError as e:
290+
error_msg = generate_helpful_error_message(e, "Environment validation failed")
291+
console.print(f"[red]Configuration Error:[/red]\n{error_msg}")
292+
raise typer.Exit(1)
291293
except Exception as e:
292-
console.print(f"[red]Error:[/red] Failed to load environment config: {e}")
294+
console.print(f"[red]Error:[/red] Failed to validate configuration: {e}")
293295
raise typer.Exit(1)
294296

295297
# Load manifest for credential validation

src/agentex/lib/sdk/config/validation.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"""
77

88
from pathlib import Path
9-
from typing import List, Optional
9+
from typing import Any, Dict, List, Optional
1010

11-
from agentex.lib.sdk.config.environment_config import AgentEnvironmentsConfig
11+
from agentex.lib.sdk.config.environment_config import AgentEnvironmentsConfig, AgentEnvironmentConfig
1212
from agentex.lib.utils.logging import make_logger
1313

1414
logger = make_logger(__name__)
@@ -43,7 +43,7 @@ def validate_environments_config(
4343
"""
4444
# Check for required environments
4545
if required_environments:
46-
missing_envs = []
46+
missing_envs: List[str] = []
4747
for env_name in required_environments:
4848
if env_name not in environments_config.environments:
4949
missing_envs.append(env_name)
@@ -65,7 +65,7 @@ def validate_environments_config(
6565
) from e
6666

6767

68-
def _validate_single_environment_config(env_name: str, env_config) -> None:
68+
def _validate_single_environment_config(env_name: str, env_config: AgentEnvironmentConfig) -> None:
6969
"""
7070
Validate a single environment configuration.
7171
@@ -76,22 +76,21 @@ def _validate_single_environment_config(env_name: str, env_config) -> None:
7676
Raises:
7777
ValueError: If validation fails
7878
"""
79-
# Validate namespace naming conventions
80-
namespace = env_config.kubernetes.namespace
81-
if not namespace:
82-
raise ValueError("Kubernetes namespace cannot be empty")
83-
84-
# Check for common namespace naming issues
85-
if namespace != namespace.lower():
86-
logger.warning(
87-
f"Namespace '{namespace}' contains uppercase letters. "
88-
"Kubernetes namespaces should be lowercase."
89-
)
90-
91-
if namespace.startswith('-') or namespace.endswith('-'):
92-
raise ValueError(
93-
f"Namespace '{namespace}' cannot start or end with hyphens"
94-
)
79+
# Validate namespace naming conventions if kubernetes config exists
80+
if env_config.kubernetes and env_config.kubernetes.namespace:
81+
namespace = env_config.kubernetes.namespace
82+
83+
# Check for common namespace naming issues
84+
if namespace != namespace.lower():
85+
logger.warning(
86+
f"Namespace '{namespace}' contains uppercase letters. "
87+
"Kubernetes namespaces should be lowercase."
88+
)
89+
90+
if namespace.startswith('-') or namespace.endswith('-'):
91+
raise ValueError(
92+
f"Namespace '{namespace}' cannot start or end with hyphens"
93+
)
9594

9695
# Validate auth principal
9796
principal = env_config.auth.principal
@@ -112,7 +111,7 @@ def _validate_single_environment_config(env_name: str, env_config) -> None:
112111
_validate_helm_overrides(env_config.helm_overrides)
113112

114113

115-
def _validate_helm_overrides(helm_overrides: dict) -> None:
114+
def _validate_helm_overrides(helm_overrides: Dict[str, Any]) -> None:
116115
"""
117116
Validate helm override configuration.
118117
@@ -130,7 +129,7 @@ def _validate_helm_overrides(helm_overrides: dict) -> None:
130129
if 'requests' in resources or 'limits' in resources:
131130
for resource_type in ['requests', 'limits']:
132131
if resource_type in resources:
133-
resource_config = resources[resource_type]
132+
resource_config: Any = resources[resource_type]
134133
if isinstance(resource_config, dict):
135134
# Check for valid resource specifications
136135
for key, value in resource_config.items():

0 commit comments

Comments
 (0)