From b4ee1b0e8fdc37641056288d86e69a39842e2faa Mon Sep 17 00:00:00 2001 From: rguichard Date: Thu, 25 Jun 2026 11:42:01 +0200 Subject: [PATCH] refactor(helm): pass chart path to helm instead of cd-ing into it process_chart() changed directory into each chart to run `helm dependency update` / `helm template .` and then cd-ed back. Pass the chart path directly (`helm dependency update `, `helm template `) so no working-directory juggling is needed. The temp output paths are absolute (mktemp), so output is unaffected. INITIAL_DIR is removed as it is no longer referenced. No behaviour change. Addresses Aikido finding on validate-helm-charts.sh:110. Co-Authored-By: Claude Opus 4.8 --- validate-helm-charts.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/validate-helm-charts.sh b/validate-helm-charts.sh index 242f56121..6e3c3cd81 100755 --- a/validate-helm-charts.sh +++ b/validate-helm-charts.sh @@ -39,10 +39,6 @@ if ! command -v helm &> /dev/null; then exit 1 fi -# Store the initial working directory -INITIAL_DIR=$(pwd) -export INITIAL_DIR - # Set base directories to scan (erpc: base chart + prd env wrapper only) DIRS_TO_SCAN=("helm/charts/erpc" "helm/environments/prd/erpc") @@ -107,25 +103,21 @@ process_chart() { # Build dependencies if Chart.yaml exists and has dependencies if [ -f "${chart_absolute_path}/Chart.yaml" ]; then if grep -q "dependencies:" "${chart_absolute_path}/Chart.yaml"; then - cd "$chart_absolute_path" - if ! helm dependency update > /dev/null 2>&1; then + if ! helm dependency update "$chart_absolute_path" > /dev/null 2>&1; then echo -e "${RED}✗ Dependency update failed for ${chart_name}${NC}" >&2 - cd "$INITIAL_DIR" rm -f "$result_file" "$result_file.lint" "$result_file.template" exit 1 fi fi # Run template validation - cd "$chart_absolute_path" - if ! helm template . 2>/dev/null | kubeconform --ignore-missing-schemas --summary --skip "$CUSTOM_RESOURCES" > "$result_file.template" 2>&1; then + if ! helm template "$chart_absolute_path" 2>/dev/null | kubeconform --ignore-missing-schemas --summary --skip "$CUSTOM_RESOURCES" > "$result_file.template" 2>&1; then echo -e "${RED}✗ Kubeconform failed for ${chart_name}${NC}" >&2 cat "$result_file.template" >&2 has_error=1 else echo -e "${GREEN}✓ Kubeconform passed for ${chart_name}${NC}" >&2 fi - cd "$INITIAL_DIR" else echo -e "${RED}No Chart.yaml found in ${chart_path}${NC}" >&2 has_error=1