Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/Development/standardize-terminology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Standardize Terminology: Environment to Deployment

This document outlines the tasks required to standardize the terminology in the codebase, replacing all instances of "environment" with "deployment" for consistency.

## Background

Currently, the codebase uses "environment" in the internal API and "deployment" in the CLI interface and user-facing messages. This inconsistency can lead to confusion for developers and users. The goal is to standardize on "deployment" throughout the codebase.

## Tasks

### 1. Update Core Models

- [ ] Update `HelmValuesConfig` class:
- [ ] Change method signatures to use "deployment" instead of "environment"
- [ ] Update docstrings and comments
- [ ] Ensure backward compatibility or provide migration path

- [ ] Update `Value` class:
- [ ] Rename `environment` parameter to `deployment` in constructor and methods
- [ ] Update docstrings and comments

### 2. Update Command Classes

- [ ] Update `SetValueCommand` class:
- [ ] Rename internal variables from "environment" to "deployment"
- [ ] Ensure all docstrings and comments use "deployment"

- [ ] Review and update other command classes that might use "environment"

### 3. Update Backend Classes

- [ ] Update `SimpleValueBackend` class:
- [ ] Rename method parameters from "environment" to "deployment"
- [ ] Update internal storage keys if necessary

- [ ] Update other backend implementations if present

### 4. Update Tests

- [ ] Update unit tests:
- [ ] Rename test variables from "environment" to "deployment"
- [ ] Update mock objects and assertions

- [ ] Update integration tests:
- [ ] Ensure all tests use "deployment" consistently

### 5. Update Documentation

- [ ] Update design documentation:
- [ ] Review and update low-level-design.md
- [ ] Review and update sequence-diagrams.md

- [ ] Update user documentation:
- [ ] Ensure all examples and explanations use "deployment"

### 6. Create Migration Plan

- [ ] Assess impact on existing configurations:
- [ ] Determine if existing configurations need to be migrated
- [ ] Create migration script if necessary

## Implementation Strategy

This change should be implemented as a single, focused PR to ensure consistency across the codebase. The PR should:

1. Not include any functional changes beyond the terminology standardization
2. Include comprehensive tests to ensure no functionality is broken
3. Update all relevant documentation

## Testing Strategy

1. Run all existing tests to ensure they pass with the updated terminology
2. Add specific tests to verify that the terminology change doesn't affect functionality
3. Manually test key workflows to ensure they work as expected

## Risks and Mitigation

- **Breaking Changes**: This change may introduce breaking changes for users who have integrated with the internal API. Consider providing a deprecation period or backward compatibility layer.
- **Documentation**: Ensure all documentation is updated to reflect the new terminology to avoid confusion.
35 changes: 25 additions & 10 deletions docs/Development/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@
- [x] Add basic path validation
- [x] Add metadata validation
- [x] Add config update
- [ ] Implement add-deployment command
- [ ] Add basic deployment validation
- [ ] Add backend validation
- [ ] Add deployment registration
- [x] Implement add-deployment command
- [x] Add basic deployment validation
- [x] Add backend validation
- [x] Add deployment registration
- [ ] Implement generate command
- [ ] Add template generation
- [ ] Add basic value substitution

- [ ] Value Management Commands
- [ ] Implement get-value command
- [ ] Add basic path validation
- [ ] Add value retrieval
- [ ] Implement set-value command
- [ ] Add basic path validation
- [ ] Add value storage
- [x] Implement set-value command
- [x] Add basic path validation
- [x] Add value storage
- [ ] Implement generate command
- [ ] Add template generation
- [ ] Add basic value substitution

#### Phase 2: Enhanced Safety & Management
- [x] Enhanced Command Infrastructure
Expand All @@ -123,6 +123,11 @@
- [ ] Add conflict detection
- [ ] Add dependency validation

- [ ] Value Management Commands
- [ ] Implement get-value command
- [ ] Add basic path validation
- [ ] Add value retrieval

- [ ] Basic Validation System
- [ ] Add PathValidator class
- [ ] Add path format validation
Expand Down Expand Up @@ -259,6 +264,16 @@
- [ ] Add missing tests
- [ ] Improve existing tests

## Code Quality and Maintenance
- [ ] Standardize terminology (environment → deployment)
- [ ] Update core models (HelmValuesConfig, Value)
- [ ] Update command classes
- [ ] Update backend classes
- [ ] Update tests
- [ ] Update documentation
- [ ] Add more comprehensive error handling
- [ ] Improve test coverage

## Development Guidelines
1. Follow TDD approach
- Write tests first
Expand Down
27 changes: 27 additions & 0 deletions helm_values_manager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from helm_values_manager.commands.add_deployment_command import AddDeploymentCommand
from helm_values_manager.commands.add_value_config_command import AddValueConfigCommand
from helm_values_manager.commands.init_command import InitCommand
from helm_values_manager.commands.set_value_command import SetValueCommand
from helm_values_manager.utils.logger import HelmLogger

COMMAND_INFO = "helm values-manager"
Expand Down Expand Up @@ -97,5 +98,31 @@ def add_deployment(
raise typer.Exit(code=1) from e


@app.command("set-value")
def set_value(
path: str = typer.Option(..., "--path", "-p", help="Configuration path (e.g., 'app.replicas')"),
deployment: str = typer.Option(
..., "--deployment", "-d", help="Deployment to set the value for (e.g., 'dev', 'prod')"
),
value: str = typer.Option(..., "--value", "-v", help="Value to set"),
):
"""Set a value for a specific path and deployment."""
try:
command = SetValueCommand()

# Create kwargs for command execution
kwargs = {
"path": path,
"environment": deployment, # Map deployment to environment for API compatibility
"value": value,
}

result = command.execute(**kwargs)
typer.echo(result)
except Exception as e:
HelmLogger.error("Failed to set value: %s", str(e))
raise typer.Exit(code=1) from e


if __name__ == "__main__":
app(prog_name=COMMAND_INFO)
62 changes: 62 additions & 0 deletions helm_values_manager/commands/set_value_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Command to set a value for a specific path and deployment."""

from typing import Optional

from helm_values_manager.commands.base_command import BaseCommand
from helm_values_manager.models.helm_values_config import HelmValuesConfig
from helm_values_manager.utils.logger import HelmLogger


class SetValueCommand(BaseCommand):
"""Command to set a value for a specific path and deployment."""

def run(self, config: Optional[HelmValuesConfig] = None, **kwargs) -> str:
"""
Set a value for a specific path and deployment.

Args:
config: The loaded configuration
**kwargs: Command arguments
- path (str): The configuration path (e.g., 'app.replicas')
- environment (str): The deployment to set the value for (e.g., 'dev', 'prod')
- value (str): The value to set

Returns:
str: Success message

Raises:
ValueError: If path or environment is empty
KeyError: If path or deployment doesn't exist in the configuration
"""
if config is None:
raise ValueError("Configuration not loaded")

path = kwargs.get("path")
if not path:
raise ValueError("Path cannot be empty")

environment = kwargs.get("environment")
if not environment:
raise ValueError("Deployment cannot be empty")

value = kwargs.get("value")

# Validate that the deployment exists
if environment not in config.deployments:
raise KeyError(f"Deployment '{environment}' not found")

try:
# Set the value for the specified path and deployment
config.set_value(path=path, environment=environment, value=value)

# Save the updated configuration
self.save_config(config)

HelmLogger.debug("Set value for path '%s' in deployment '%s'", path, environment)
return f"Successfully set value for path '{path}' in deployment '{environment}'"
except KeyError as e:
HelmLogger.error("Failed to set value: %s", str(e))
raise
except Exception as e:
HelmLogger.error("Failed to set value: %s", str(e))
raise
114 changes: 114 additions & 0 deletions tests/integration/test_cli_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,117 @@ def test_add_deployment_no_config(plugin_install, tmp_path):
stdout, stderr, returncode = run_helm_command(["values-manager", "add-deployment", "dev"])
assert returncode == 1
assert "Configuration file helm-values.json not found" in stderr


def test_set_value_command(plugin_install, tmp_path):
"""Test that the set-value command works correctly."""
# Create a working directory
work_dir = tmp_path / "test_set_value"
work_dir.mkdir()
os.chdir(work_dir)

# Initialize the config
init_stdout, init_stderr, init_returncode = run_helm_command(
["values-manager", "init", "--release", "test-release"]
)
assert init_returncode == 0
assert Path("helm-values.json").exists()

# Add a deployment
add_deployment_stdout, add_deployment_stderr, add_deployment_returncode = run_helm_command(
["values-manager", "add-deployment", "dev"]
)
assert add_deployment_returncode == 0

# Add a value config
add_value_config_stdout, add_value_config_stderr, add_value_config_returncode = run_helm_command(
[
"values-manager",
"add-value-config",
"--path",
"app.replicas",
"--description",
"Number of replicas",
"--required",
]
)
assert add_value_config_returncode == 0

# Set a value
stdout, stderr, returncode = run_helm_command(
["values-manager", "set-value", "--path", "app.replicas", "--deployment", "dev", "--value", "3"]
)
assert returncode == 0
assert "Successfully set value for path 'app.replicas' in deployment 'dev'" in stdout

# Verify the value was set
with open("helm-values.json", "r") as f:
config = json.load(f)

# The value itself is stored in the backend, not directly in the config file
# But we can verify that the path exists in the config
assert any(path["path"] == "app.replicas" for path in config["config"])


def test_set_value_nonexistent_path(plugin_install, tmp_path):
"""Test that setting a value for a nonexistent path fails with the correct error message."""
# Create a working directory
work_dir = tmp_path / "test_set_value_nonexistent_path"
work_dir.mkdir()
os.chdir(work_dir)

# Initialize the config
init_stdout, init_stderr, init_returncode = run_helm_command(
["values-manager", "init", "--release", "test-release"]
)
assert init_returncode == 0
assert Path("helm-values.json").exists()

# Add a deployment
add_deployment_stdout, add_deployment_stderr, add_deployment_returncode = run_helm_command(
["values-manager", "add-deployment", "dev"]
)
assert add_deployment_returncode == 0

# Try to set a value for a nonexistent path
stdout, stderr, returncode = run_helm_command(
["values-manager", "set-value", "--path", "nonexistent.path", "--deployment", "dev", "--value", "3"]
)
assert returncode == 1
assert "Path nonexistent.path not found" in stderr


def test_set_value_nonexistent_deployment(plugin_install, tmp_path):
"""Test that setting a value for a nonexistent deployment fails with the correct error message."""
# Create a working directory
work_dir = tmp_path / "test_set_value_nonexistent_deployment"
work_dir.mkdir()
os.chdir(work_dir)

# Initialize the config
init_stdout, init_stderr, init_returncode = run_helm_command(
["values-manager", "init", "--release", "test-release"]
)
assert init_returncode == 0
assert Path("helm-values.json").exists()

# Add a value config
add_value_config_stdout, add_value_config_stderr, add_value_config_returncode = run_helm_command(
[
"values-manager",
"add-value-config",
"--path",
"app.replicas",
"--description",
"Number of replicas",
"--required",
]
)
assert add_value_config_returncode == 0

# Try to set a value for a nonexistent deployment
stdout, stderr, returncode = run_helm_command(
["values-manager", "set-value", "--path", "app.replicas", "--deployment", "nonexistent", "--value", "3"]
)
assert returncode == 1
assert "Deployment 'nonexistent' not found" in stderr
Loading