From 0350f3e0124b41cc2f3d3ef5b4480d55933cdbe8 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 13:57:56 +0200 Subject: [PATCH 1/6] chore: Add basic script to upgrade most helm-charts --- .scripts/update_helm_charts.py | 106 ++++++++++++++++++ shell.nix | 3 + .../observability/opentelemetry-operator.yaml | 2 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100755 .scripts/update_helm_charts.py diff --git a/.scripts/update_helm_charts.py b/.scripts/update_helm_charts.py new file mode 100755 index 00000000..6cda3950 --- /dev/null +++ b/.scripts/update_helm_charts.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python + +import os +import subprocess +import yaml +from typing import Tuple, Set + + +def run_helm_repo_add(repo_name: str, repo_url: str) -> None: + try: + subprocess.run(["helm", "repo", "add", repo_name, repo_url], check=True) + except subprocess.CalledProcessError as e: + if "already exists" in e.stderr.decode() if e.stderr else str(e): + pass # Ignore "already exists" error + else: + raise + + +def run_helm_repo_update() -> None: + subprocess.run(["helm", "repo", "update"], check=True) + + +def get_chart_and_app_version(repo_name: str, chart_name: str) -> Tuple[str, str]: + full_chart = f"{repo_name}/{chart_name}" + result = subprocess.run( + ["helm", "show", "chart", full_chart], + capture_output=True, + text=True, + check=True + ) + chart_yaml = yaml.safe_load(result.stdout) + return chart_yaml["version"], chart_yaml["appVersion"] + + +def process_yaml_files(top_dir: str) -> None: + seen_repos: Set[str] = set() + + for root, _, files in os.walk(top_dir): + for file in files: + if not file.endswith(".yaml"): + continue + + filepath = os.path.join(root, file) + + try: + with open(filepath, "r") as f: + raw_lines = f.readlines() + + try: + first_doc = yaml.safe_load("".join(raw_lines)) + except yaml.YAMLError as e: + if "expected a single document" in str(e): + continue # silently skip multi-doc YAMLs + print(f"⚠️ Skipping invalid YAML: {filepath}") + continue + + if not isinstance(first_doc, dict): + continue + + if not ( + "releaseName" in first_doc + and "version" in first_doc + and "repo" in first_doc + and "name" in first_doc + ): + continue + + repo_info = first_doc["repo"] + chart_name = first_doc["name"] + repo_name = repo_info.get("name") + repo_url = repo_info.get("url") + + if not repo_name or not repo_url: + continue + + if repo_name not in seen_repos: + run_helm_repo_add(repo_name, repo_url) + seen_repos.add(repo_name) + + # print(f"📦 Updating {filepath} -> {repo_name}/{chart_name}") + new_chart_version, new_app_version = get_chart_and_app_version(repo_name, chart_name) + + updated_lines = [] + for line in raw_lines: + if line.strip().startswith("version:"): + new_line = f'version: {new_chart_version} # {new_app_version}\n' + updated_lines.append(new_line) + else: + updated_lines.append(line) + + with open(filepath, "w") as f: + f.writelines(updated_lines) + + print(f"✅ Updated {filepath}") + + except Exception as e: + print(f"⚠️ Error processing {filepath}: {e}") + +if __name__ == "__main__": + print('⚠️⚠️⚠️ This script is best-effort! Always check the result using "git diff"! ⚠️⚠️⚠️') + print('Notably, it skips invalid YAMLs, which can be the case because we sometimes use templating syntax, even for helm-chart definitions') + print('Please judge on the skipped files if they contain a helm-chart and should be manually bumped') + print('The script can be improved to handle such files in the future') + print() + + process_yaml_files(".") diff --git a/shell.nix b/shell.nix index 63d72e2c..4d2eb190 100644 --- a/shell.nix +++ b/shell.nix @@ -2,5 +2,8 @@ pkgs.mkShell { packages = with pkgs; [ gettext # envsubst + (pkgs.python3.withPackages (python-pkgs: [ + python-pkgs.pyyaml + ])) ]; } diff --git a/stacks/observability/opentelemetry-operator.yaml b/stacks/observability/opentelemetry-operator.yaml index df564e79..8abf3f9d 100644 --- a/stacks/observability/opentelemetry-operator.yaml +++ b/stacks/observability/opentelemetry-operator.yaml @@ -5,7 +5,7 @@ name: opentelemetry-operator repo: name: opentelemetry-operator url: https://open-telemetry.github.io/opentelemetry-helm-charts -version: 0.91.0 # 0.127.0 +version: 0.91.1 # 0.127.0 options: admissionWebhooks: certManager: From b2ef4e5da2eda908828debe01c48e5cf7f3cc9c6 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 14:05:41 +0200 Subject: [PATCH 2/6] Mention in issue template --- .github/ISSUE_TEMPLATE/pre-release-chart-updates.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md b/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md index 30296890..634a3dc4 100644 --- a/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md +++ b/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md @@ -15,6 +15,11 @@ Most of the charts are located in the `stacks/_templated` folder. Additional fol `stacks/observability` and `stacks/signal-processing`. It is recommended to search for `releaseName` to find all referenced charts. +### Best-effort helper script + +There is a best-effort helper scripts, which might help you: `.scripts/update_helm_charts.py`. +Please read the warnings it prints on startup and keep them in mind. + ### Update Instructions These instructions help to update the charts: From 3a478c9cc5640aaa3a717f6b90fe388424d68811 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 14:06:15 +0200 Subject: [PATCH 3/6] typo --- .github/ISSUE_TEMPLATE/pre-release-chart-updates.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md b/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md index 634a3dc4..5cd0bffc 100644 --- a/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md +++ b/.github/ISSUE_TEMPLATE/pre-release-chart-updates.md @@ -17,7 +17,7 @@ to find all referenced charts. ### Best-effort helper script -There is a best-effort helper scripts, which might help you: `.scripts/update_helm_charts.py`. +There is a best-effort helper script which might help you: `.scripts/update_helm_charts.py`. Please read the warnings it prints on startup and keep them in mind. ### Update Instructions From e6e5dad3f4b5fd39710334a1d0622a6ae93855cc Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 14:09:44 +0200 Subject: [PATCH 4/6] fix: Update repos --- .scripts/update_helm_charts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.scripts/update_helm_charts.py b/.scripts/update_helm_charts.py index 6cda3950..a06fde14 100755 --- a/.scripts/update_helm_charts.py +++ b/.scripts/update_helm_charts.py @@ -5,7 +5,6 @@ import yaml from typing import Tuple, Set - def run_helm_repo_add(repo_name: str, repo_url: str) -> None: try: subprocess.run(["helm", "repo", "add", repo_name, repo_url], check=True) @@ -16,8 +15,8 @@ def run_helm_repo_add(repo_name: str, repo_url: str) -> None: raise -def run_helm_repo_update() -> None: - subprocess.run(["helm", "repo", "update"], check=True) +def run_helm_repo_update(repo_name: str) -> None: + subprocess.run(["helm", "repo", "update", repo_name], check=True) def get_chart_and_app_version(repo_name: str, chart_name: str) -> Tuple[str, str]: @@ -77,6 +76,8 @@ def process_yaml_files(top_dir: str) -> None: run_helm_repo_add(repo_name, repo_url) seen_repos.add(repo_name) + run_helm_repo_update(repo_name) + # print(f"📦 Updating {filepath} -> {repo_name}/{chart_name}") new_chart_version, new_app_version = get_chart_and_app_version(repo_name, chart_name) From 058012c5c4a615806c56c8a12067d1e49b17d229 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 14:11:50 +0200 Subject: [PATCH 5/6] Update shell.nix --- shell.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shell.nix b/shell.nix index 4d2eb190..d21f0633 100644 --- a/shell.nix +++ b/shell.nix @@ -2,8 +2,9 @@ pkgs.mkShell { packages = with pkgs; [ gettext # envsubst - (pkgs.python3.withPackages (python-pkgs: [ - python-pkgs.pyyaml - ])) + + # Needed by .scripts/update_helm_charts.py + python311Packages.pyyaml + kubernetes-helm ]; } From add657f2162680a5561d6a690c23737077dbd7c7 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 16 Jul 2025 14:12:49 +0200 Subject: [PATCH 6/6] revert bump --- stacks/observability/opentelemetry-operator.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stacks/observability/opentelemetry-operator.yaml b/stacks/observability/opentelemetry-operator.yaml index 8abf3f9d..df564e79 100644 --- a/stacks/observability/opentelemetry-operator.yaml +++ b/stacks/observability/opentelemetry-operator.yaml @@ -5,7 +5,7 @@ name: opentelemetry-operator repo: name: opentelemetry-operator url: https://open-telemetry.github.io/opentelemetry-helm-charts -version: 0.91.1 # 0.127.0 +version: 0.91.0 # 0.127.0 options: admissionWebhooks: certManager: