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
94 changes: 73 additions & 21 deletions .scripts/update_helm_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
import subprocess
import yaml
from typing import Tuple, Set
from textwrap import dedent


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
result = subprocess.run(
["helm", "repo", "add", repo_name, repo_url, "--force-update"],
capture_output=True,
check=True,
)
if result.returncode == 0:
print(f"✅ Added/Updated {repo_name} ({repo_url})")
else:
print(
f"⚠️ There was a problem Adding/Updating {repo_name} ({repo_url}): {result.stderr}"
)


def run_helm_repo_update(repo_name: str) -> None:
subprocess.run(["helm", "repo", "update", repo_name], check=True)
def local_repo_list():
result = subprocess.run(
["helm", "repo", "list", "-o", "yaml"],
capture_output=True,
text=True,
check=True,
)
return yaml.safe_load(result.stdout)


def get_chart_and_app_version(repo_name: str, chart_name: str) -> Tuple[str, str]:
Expand All @@ -25,14 +37,17 @@ def get_chart_and_app_version(repo_name: str, chart_name: str) -> Tuple[str, str
["helm", "show", "chart", full_chart],
capture_output=True,
text=True,
check=True
check=True,
)
chart_yaml = yaml.safe_load(result.stdout)
return chart_yaml["version"], chart_yaml["appVersion"]
# Some charts don't have an appVersion and as such we fallback to a default
# value to not cause lookup errors.
return chart_yaml["version"], chart_yaml.setdefault("appVersion", "Not present")
Comment thread
NickLarsenNZ marked this conversation as resolved.


def process_yaml_files(top_dir: str) -> None:
seen_repos: Set[str] = set()
local_repos = local_repo_list()

for root, _, files in os.walk(top_dir):
for file in files:
Expand Down Expand Up @@ -72,19 +87,47 @@ def process_yaml_files(top_dir: str) -> None:
if not repo_name or not repo_url:
continue

# At this point, it appears to be a Helm Chart manifest.

# Skip Vector, as we currently keep it tied to the version that the product sidecars use.abs
# Looking forward to swapping the transport with OTLP.
if chart_name == "vector":
raise Exception(
"Skipping vector. Ensure it is at the same version as the product sidecars"
)
continue

chart_version = first_doc["version"]
# Skip chart versions which seem to be templated.
if chart_version.startswith("{{"):
Comment thread
NickLarsenNZ marked this conversation as resolved.
continue

local_repo = next(
(repo for repo in local_repos if repo["name"] == repo_name), None
)
if local_repo is not None:
Comment thread
Techassi marked this conversation as resolved.
local_repo_url = local_repo["url"]
if local_repo_url != repo_url:
raise Exception(
dedent(f"""
You have a local repo named {repo_name} pointing to {local_repo_url}, but the stack/demo wants {repo_url}
Either delete or update your local repo URL, or update the stack/demo repo name so it doesn't conflict
""")
)

if repo_name not in seen_repos:
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)
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'
if line.startswith("version:"):
new_line = f"version: {new_chart_version} # appVersion: {new_app_version}\n"
updated_lines.append(new_line)
else:
updated_lines.append(line)
Expand All @@ -95,13 +138,22 @@ def process_yaml_files(top_dir: str) -> None:
print(f"✅ Updated {filepath}")

except Exception as e:
# If debugging, you can get the exception line number like this:
# _, _, tb = os.sys.exc_info()
# lineno = tb.tb_lineno
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()
print(
dedent("""
⚠️⚠️⚠️ This script is best-effort! Always check the result using "git diff"! ⚠️⚠️⚠️
Notably, it skips invalid YAMLs, which can be the case because we sometimes use templating syntax, even for helm-chart definitions.
In those cases, use quotes around templated values, or otherwise comments for templated blocks.

Please judge on the skipped files if they contain a helm-chart and should be manually bumped.
The script can be improved to handle such files in the future.
""")
)

process_yaml_files(".")
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ spec:
namespace: stackable-airflow
labels:
stackable.tech/vendor: Stackable
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
type: Opaque
2 changes: 1 addition & 1 deletion demos/argo-cd-git-ops/manifests/airflow/airflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: airflow
labels:
stackable.tech/vendor: Stackable
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
spec:
image:
productVersion: 3.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ spec:
namespace: stackable-airflow
labels:
stackable.tech/vendor: Stackable
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
type: Opaque
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ spec:
namespace: stackable-airflow
labels:
stackable.tech/vendor: Stackable
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
type: Opaque
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ spec:
namespace: minio
labels:
stackable.tech/vendor: Stackable
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
type: Opaque
6 changes: 3 additions & 3 deletions stacks/_templates/argo-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ name: argo-cd
repo:
name: argo-cd
url: https://argoproj.github.io/argo-helm
version: 9.4.10 # v3.3.3
version: 10.1.3 # appVersion: v3.4.5

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, 3.4.5 just landed :D

options:
global:
additionalLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
configs:
secret:
Expand Down
8 changes: 4 additions & 4 deletions stacks/_templates/minio-distributed-small-tls/values.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
additionalLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
podLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
rootUser: admin
rootPassword: adminadmin
Expand Down
8 changes: 4 additions & 4 deletions stacks/_templates/minio-distributed-tls/values.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
additionalLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
podLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
rootUser: admin
rootPassword: adminadmin
Expand Down
12 changes: 6 additions & 6 deletions stacks/_templates/minio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ name: minio
repo:
name: minio
url: https://charts.min.io/
version: 5.4.0 # RELEASE.2024-12-18T13-15-44Z
version: 5.4.0 # appVersion: RELEASE.2024-12-18T13-15-44Z
options:
additionalLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
podLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
rootUser: admin
rootPassword: {{ minioAdminPassword }}
rootPassword: "{{ minioAdminPassword }}"
mode: standalone
persistence:
size: 10Gi
Expand Down
10 changes: 5 additions & 5 deletions stacks/_templates/opensearch-dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ name: opensearch-dashboards
repo:
name: opensearch-dashboards
url: https://opensearch-project.github.io/helm-charts
version: {{ opensearchVersion }}
version: "{{ opensearchVersion }}"
options:
image:
repository: oci.stackable.tech/sdp/opensearch-dashboards
tag: "{{ opensearchVersion }}-stackable{{ stackableReleaseVersion }}"
labels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
service:
type: NodePort
Expand All @@ -25,11 +25,11 @@ options:
stackable.tech/logging-credentials-secret: opensearch-user
labels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
opensearchHosts: null # Use the discovery ConfigMap instead
extraEnvs:
Expand Down
6 changes: 3 additions & 3 deletions stacks/_templates/postgresql-airflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ name: postgresql
repo:
name: bitnami
url: https://charts.bitnami.com/bitnami/
version: 18.5.6 # 18.3.0
version: 18.7.13 # appVersion: 18.4.0
options:
commonLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
auth:
username: airflow
Expand Down
6 changes: 3 additions & 3 deletions stacks/_templates/postgresql-druid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ name: postgresql
repo:
name: bitnami
url: https://charts.bitnami.com/bitnami/
version: 18.5.6 # 18.3.0
version: 18.7.13 # appVersion: 18.4.0
options:
commonLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
auth:
username: druid
Expand Down
6 changes: 3 additions & 3 deletions stacks/_templates/postgresql-hive-iceberg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ name: postgresql
repo:
name: bitnami
url: https://charts.bitnami.com/bitnami/
version: 18.5.6 # 18.3.0
version: 18.7.13 # appVersion: 18.4.0
options:
commonLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
auth:
username: hive
Expand Down
6 changes: 3 additions & 3 deletions stacks/_templates/postgresql-hive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ name: postgresql
repo:
name: bitnami
url: https://charts.bitnami.com/bitnami/
version: 18.5.6 # 18.3.0
version: 18.7.13 # appVersion: 18.4.0
options:
commonLabels:
stackable.tech/vendor: Stackable
stackable.tech/stack: {{ STACK }}
stackable.tech/stack: "{{ STACK }}"
# The following is a Jinja2 template directive, not a regular comment.
# The `#` prefix is required to prevent YAML parsing errors, but Jinja2 still processes it.
# {% if DEMO is defined %}
stackable.tech/demo: {{ DEMO }}
stackable.tech/demo: "{{ DEMO }}"
# {% endif %}
auth:
username: hive
Expand Down
Loading
Loading