Skip to content

Commit 36aec3d

Browse files
authored
Merge pull request #18 from Zipstack/feature/add-value-config
feat: Implement add-value-config command and ADR for custom config paths
2 parents c7a8dfd + 7037c22 commit 36aec3d

File tree

10 files changed

+619
-20
lines changed

10 files changed

+619
-20
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# 9. Custom Configuration File Paths
2+
3+
Date: 2025-02-27
4+
5+
## Status
6+
7+
Proposed
8+
9+
## Context
10+
11+
Currently, the Helm Values Manager uses hardcoded file paths for its configuration and lock files:
12+
- Configuration file: `helm-values.json`
13+
- Lock file: `.helm-values.lock`
14+
15+
These paths are defined in the `BaseCommand` class and used across all commands. This approach has several limitations:
16+
17+
1. **Limited Flexibility**: Users cannot manage multiple configurations in the same directory
18+
2. **Naming Constraints**: Organizations may have specific naming conventions that conflict with our hardcoded names
19+
3. **Integration Challenges**: Difficult to integrate with existing systems that might have their own file organization
20+
4. **Location Restrictions**: Configuration files must be in the current working directory
21+
22+
Users have expressed interest in being able to specify custom file paths for their configuration files, which would address these limitations and provide greater flexibility.
23+
24+
## Decision
25+
26+
We will enhance the Helm Values Manager to support custom configuration file paths by:
27+
28+
1. **Adding a `--config-file` option to all commands**:
29+
```python
30+
config_file: str = typer.Option(
31+
"helm-values.json",
32+
"--config-file",
33+
"-c",
34+
help="Path to the configuration file"
35+
)
36+
```
37+
38+
2. **Updating the `BaseCommand` class to accept a config file path**:
39+
```python
40+
def __init__(self, config_file: str = "helm-values.json") -> None:
41+
"""Initialize the base command.
42+
43+
Args:
44+
config_file: Path to the configuration file
45+
"""
46+
self.config_file = config_file
47+
self.lock_file = self._generate_lock_file_path(config_file)
48+
self._lock_fd: Optional[int] = None
49+
```
50+
51+
3. **Generating the lock file name based on the config file path**:
52+
```python
53+
def _generate_lock_file_path(self, config_file: str) -> str:
54+
"""Generate the lock file path based on the config file path.
55+
56+
Args:
57+
config_file: Path to the configuration file
58+
59+
Returns:
60+
str: Path to the lock file
61+
"""
62+
# Expand user home directory if present (e.g., ~/configs)
63+
expanded_path = os.path.expanduser(config_file)
64+
config_path = Path(expanded_path)
65+
66+
# Check if the path is a directory
67+
if config_path.is_dir():
68+
# Use default filename in the specified directory
69+
config_path = config_path / "helm-values.json"
70+
71+
# Create lock file name based on the config file stem (name without extension)
72+
lock_file = f".{config_path.stem}.lock"
73+
return str(config_path.parent / lock_file)
74+
```
75+
76+
4. **Propagating the config file path to all command instances**:
77+
```python
78+
@app.command()
79+
def init(
80+
release_name: str = typer.Option(..., "--release", "-r", help="Name of the Helm release"),
81+
config_file: str = typer.Option("helm-values.json", "--config-file", "-c", help="Path to the configuration file"),
82+
):
83+
"""Initialize a new helm-values configuration."""
84+
command = InitCommand(config_file=config_file)
85+
result = command.execute(release_name=release_name)
86+
echo(result)
87+
```
88+
89+
## Consequences
90+
91+
### Positive
92+
93+
1. **Increased Flexibility**: Users can manage multiple configurations in the same directory
94+
2. **Custom Naming**: Organizations can follow their own naming conventions
95+
3. **Better Integration**: Easier to integrate with existing systems and workflows
96+
4. **Location Freedom**: Configuration files can be placed in any directory
97+
98+
### Negative
99+
100+
1. **API Change**: All command functions need to be updated to accept the new parameter
101+
2. **Complexity**: Slightly more complex code to handle different file paths
102+
3. **Testing**: Additional test cases needed to verify the functionality
103+
4. **Documentation**: Documentation needs to be updated to reflect the new option
104+
105+
### Neutral
106+
107+
1. **Backward Compatibility**: Default values ensure backward compatibility with existing usage
108+
2. **Lock File Naming**: Lock files will be named based on the configuration file name
109+
110+
## Implementation Notes
111+
112+
1. The implementation should be backward compatible, using the current hardcoded paths as defaults
113+
2. All commands should propagate the config file path to their respective command instances
114+
3. Documentation should be updated to reflect the new option
115+
4. Tests should be added to verify the functionality with custom file paths
116+
117+
## Related Issues
118+
119+
- GitHub Issue [#17](https://github.com/Zipstack/helm-values-manager/issues/17): Support for custom configuration file paths
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# ADR-010: Configuration Update and Merge
2+
3+
Date: 2025-02-27
4+
5+
## Status
6+
7+
Proposed
8+
9+
## Context
10+
11+
Chart owners may update their configuration schema over time, adding new configuration paths, modifying metadata, or removing obsolete paths. Users who have already configured their deployments need a way to incorporate these updates without losing their existing configurations.
12+
13+
Currently, the Helm Values Manager does not provide a mechanism to update an existing configuration with changes from a new version. This leads to several challenges:
14+
15+
1. Users must manually identify and apply changes between configuration versions
16+
2. There's a risk of missing new required configuration paths
17+
3. Users may lose their existing values when updating to a new configuration
18+
4. Conflicts between user customizations and chart owner updates are difficult to resolve
19+
20+
A structured approach to configuration updates would improve the user experience and reduce the risk of configuration errors.
21+
22+
## Decision
23+
24+
We will implement a configuration update and merge feature that allows users to incorporate changes from a new configuration file while preserving their existing values and deployments.
25+
26+
The feature will:
27+
28+
1. Compare the current configuration with the new one to identify:
29+
- Added configuration paths
30+
- Removed configuration paths
31+
- Modified metadata (description, required, sensitive flags)
32+
- Potential conflicts
33+
34+
2. Provide multiple merge strategies:
35+
- "Smart" (default): Preserve user values while adopting new metadata and paths
36+
- "Theirs": Prefer the new configuration but keep existing values where possible
37+
- "Ours": Prefer the existing configuration but add new paths
38+
39+
3. Validate the merged configuration to ensure it meets all requirements
40+
- Identify missing required values
41+
- Ensure all paths have valid values for their environments
42+
43+
4. Provide clear reporting of changes and required actions
44+
45+
This will be implemented as a new `update-config` command in the CLI.
46+
47+
## Consequences
48+
49+
### Positive
50+
51+
- Users can easily update their configurations when chart owners release updates
52+
- Existing user values are preserved during updates
53+
- New required configurations are clearly identified
54+
- The risk of missing important configuration changes is reduced
55+
- The update process becomes more transparent and less error-prone
56+
57+
### Negative
58+
59+
- Adds complexity to the codebase
60+
- May require additional schema versioning to handle major changes
61+
- Conflict resolution might still require manual intervention in complex cases
62+
63+
### Neutral
64+
65+
- Users will need to learn a new command and its options
66+
- May need to adjust the configuration schema to better support versioning and updates
67+
68+
## Implementation Notes
69+
70+
The implementation will require:
71+
72+
1. A new `UpdateConfigCommand` class that extends `BaseCommand`
73+
2. Configuration comparison logic to identify differences
74+
3. Merge strategies to combine configurations
75+
4. Validation to ensure the merged configuration is valid
76+
5. Reporting to communicate changes and required actions
77+
78+
The command will be exposed through the CLI as:
79+
80+
```
81+
helm values update-config [source-file] [--strategy=smart|theirs|ours] [--report-only]
82+
```
83+
84+
## Related Issues
85+
86+
- GitHub Issue [#19](https://github.com/Zipstack/helm-values-manager/issues/19): Configuration Update and Merge Feature

docs/ADRs/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This directory contains Architecture Decision Records (ADRs) for the Helm Values
55
## What is an ADR?
66
An Architecture Decision Record (ADR) is a document that captures an important architectural decision made along with its context and consequences.
77

8+
## Creating New ADRs
9+
10+
For new ADRs, use the [ADR template](adr-template.md) as a starting point.
11+
812
## ADR Index
913

1014
### [ADR-001: Helm Values Manager as a Helm Plugin](001-helm-values-manager.md)
@@ -61,20 +65,16 @@ An Architecture Decision Record (ADR) is a document that captures an important a
6165
- **Decision**: Remove registry in favor of direct command instantiation
6266
- **Impact**: Simplifies code and aligns better with Typer's design
6367

64-
## ADR Template
65-
For new ADRs, use this template:
66-
```markdown
67-
# ADR-NNN: Title
68-
69-
## Status
70-
[Proposed | Accepted | Deprecated | Superseded]
71-
72-
## Context
73-
What is the issue that we're seeing that is motivating this decision or change?
74-
75-
## Decision
76-
What is the change that we're proposing and/or doing?
68+
### [ADR-009: Custom Configuration File Paths](009-custom-configuration-file-paths.md)
69+
- **Status**: Proposed
70+
- **Context**: Limited flexibility with hardcoded configuration file paths
71+
- **Decision**: Add support for custom configuration file paths
72+
- **Impact**: Increases flexibility and improves integration capabilities
73+
- **Dependencies**: ADR-001
7774

78-
## Consequences
79-
What becomes easier or more difficult to do because of this change?
80-
```
75+
### [ADR-010: Configuration Update and Merge](010-configuration-update-and-merge.md)
76+
- **Status**: Proposed
77+
- **Context**: Need to incorporate chart owner configuration updates without losing user customizations
78+
- **Decision**: Implement configuration comparison and smart merging with multiple strategies
79+
- **Impact**: Simplifies configuration updates and reduces risk of missing required changes
80+
- **Dependencies**: ADR-001

docs/ADRs/adr-template.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ADR-NNN: Title
2+
3+
Date: YYYY-MM-DD
4+
5+
## Status
6+
7+
[Proposed | Accepted | Deprecated | Superseded]
8+
9+
## Context
10+
11+
What is the issue that we're seeing that is motivating this decision or change?
12+
13+
## Decision
14+
15+
What is the change that we're proposing and/or doing?
16+
17+
## Consequences
18+
19+
### Positive
20+
21+
What becomes easier because of this change?
22+
23+
### Negative
24+
25+
What becomes more difficult because of this change?
26+
27+
### Neutral
28+
29+
What other effects does this change have?
30+
31+
## Implementation Notes
32+
33+
Additional notes on implementation details, if applicable.
34+
35+
## Related Issues
36+
37+
- GitHub Issue #[TBD]: Related issue title

docs/Development/tasks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@
8989
- [x] Add empty config initialization
9090
- [x] Add config file creation
9191
- [x] Add schema template generation
92-
- [ ] Implement add-value-config command
93-
- [ ] Add basic path validation
94-
- [ ] Add metadata validation
95-
- [ ] Add config update
92+
- [x] Implement add-value-config command
93+
- [x] Add basic path validation
94+
- [x] Add metadata validation
95+
- [x] Add config update
9696
- [ ] Implement add-deployment command
9797
- [ ] Add basic deployment validation
9898
- [ ] Add backend validation

helm_values_manager/cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Command line interface for the helm-values-manager plugin."""
22

3+
from typing import Optional
4+
35
import typer
46

7+
from helm_values_manager.commands.add_value_config_command import AddValueConfigCommand
58
from helm_values_manager.commands.init_command import InitCommand
69
from helm_values_manager.utils.logger import HelmLogger
710

@@ -42,5 +45,36 @@ def init(
4245
raise typer.Exit(code=1) from e
4346

4447

48+
@app.command("add-value-config")
49+
def add_value_config(
50+
path: str = typer.Option(..., "--path", "-p", help="Configuration path (e.g., 'app.replicas')"),
51+
description: Optional[str] = typer.Option(
52+
None, "--description", "-d", help="Description of what this configuration does"
53+
),
54+
required: bool = typer.Option(False, "--required", "-r", help="Whether this configuration is required"),
55+
sensitive: bool = typer.Option(
56+
False,
57+
"--sensitive",
58+
"-s",
59+
help="Whether this configuration contains sensitive data (coming in v0.2.0)",
60+
hidden=True, # Hide from help text until v0.2.0
61+
),
62+
):
63+
"""Add a new value configuration with metadata."""
64+
try:
65+
command = AddValueConfigCommand()
66+
67+
# Add warning for sensitive flag until it's fully implemented
68+
if sensitive:
69+
HelmLogger.warning("Sensitive value support will be available in version 0.2.0. Flag will be ignored.")
70+
sensitive = False # Ignore the flag for now
71+
72+
result = command.execute(path=path, description=description, required=required, sensitive=sensitive)
73+
typer.echo(result)
74+
except Exception as e:
75+
HelmLogger.error("Failed to add value config: %s", str(e))
76+
raise typer.Exit(code=1) from e
77+
78+
4579
if __name__ == "__main__":
4680
app(prog_name=COMMAND_INFO)

0 commit comments

Comments
 (0)