Remove post-processing for PVC annotations

This commit is contained in:
Prathamesh Musale 2025-12-03 15:29:25 +05:30
parent 6586afc6e8
commit 0878240c26

View File

@ -72,44 +72,6 @@ def _wrap_job_templates_with_conditionals(chart_dir: Path, jobs: list) -> None:
print(f"Wrapped job template with conditional: {job_template_file.name}")
def _add_pvc_retention_policy(chart_dir: Path) -> None:
"""
Add helm.sh/resource-policy: keep annotation to PVC templates.
This ensures PVCs are not deleted when the Helm release is uninstalled,
preserving data for future deployments or job executions.
"""
templates_dir = chart_dir / "templates"
if not templates_dir.exists():
return
yaml = get_yaml()
# Find all PVC template files
pvc_files = list(templates_dir.glob("*-persistentvolumeclaim.yaml"))
for pvc_file in pvc_files:
try:
# Read the PVC template
content = yaml.load(open(pvc_file, "r"))
# Add the resource policy annotation
if "metadata" not in content:
content["metadata"] = {}
if "annotations" not in content["metadata"]:
content["metadata"]["annotations"] = {}
content["metadata"]["annotations"]["helm.sh/resource-policy"] = "keep"
# Write back
with open(pvc_file, "w") as f:
yaml.dump(content, f)
if opts.o.debug:
print(f"Added retention policy to: {pvc_file.name}")
except Exception as e:
if opts.o.debug:
print(f"Warning: Failed to add retention policy to {pvc_file.name}: {e}")
def _post_process_chart(chart_dir: Path, chart_name: str, jobs: list) -> None:
@ -119,7 +81,6 @@ def _post_process_chart(chart_dir: Path, chart_name: str, jobs: list) -> None:
Fixes:
1. Chart.yaml name, description and keywords
2. Add conditional wrappers to job templates (default: disabled)
3. Add resource retention policy to PVCs (prevent deletion on uninstall)
TODO:
- Add defaultMode: 0755 to ConfigMap volumes containing scripts (.sh files)
@ -148,9 +109,6 @@ def _post_process_chart(chart_dir: Path, chart_name: str, jobs: list) -> None:
if jobs:
_wrap_job_templates_with_conditionals(chart_dir, jobs)
# Add resource retention policy to PVCs
_add_pvc_retention_policy(chart_dir)
def generate_helm_chart(stack_path: str, spec_file: str, deployment_dir_path: Path) -> None:
"""