Add pre-commit to update release manifest #211

Merged
nbelouin merged 1 commits from nbelouin/Factory:pre-commit-manifest into main 2025-07-29 11:27:57 +02:00
4 changed files with 148 additions and 99 deletions

View File

@@ -17,7 +17,7 @@ jobs:
object-format: 'sha256'
- name: Setup dependencies
run: |
zypper in -y python3-PyYAML
zypper in -y python3-ruamel.yaml
- name: Check release manifest
run: |
python3 .obs/manifest-check.py
python3 .obs/manifest-check.py --check

51
.obs/manifest-check.py Normal file → Executable file
View File

@@ -1,11 +1,15 @@
#!/usr/bin/python3
import yaml
import ruamel.yaml
import pathlib
import argparse
import sys
yaml = ruamel.yaml.YAML()
def get_chart_version(chart_name: str) -> str:
with open(f"./{chart_name}-chart/Chart.yaml") as f:
chart = yaml.safe_load(f)
chart = yaml.load(f)
steven.hardy marked this conversation as resolved Outdated
In future I wonder if we could also add validation for k3s/RKE2, e.g parsing https://github.com/k3s-io/k3s/tree/v1.32.4%2Bk3s1/manifests and https://github.com/rancher/rke2/blob/v1.32.4%2Brke2r1/charts/chart_versions.yaml ?

I'd rather see that as a part of the renovate-like process we want, but can be envisioned. I just would not do this as a pre-commit hook as we don't want "random" PRs to contain upgrades to non-related components.
Here we just seek to keep the charts version in sync between the charts definition and release manifest.

I'd rather see that as a part of the renovate-like process we want, but can be envisioned. I just would not do this as a pre-commit hook as we don't want "random" PRs to contain upgrades to non-related components. Here we just seek to keep the charts version in sync between the charts definition and release manifest.

Sounds good, we can consider other approaches in future, just wanted to mention it :)

Sounds good, we can consider other approaches in future, just wanted to mention it :)
return chart["version"]
def get_charts(chart):
@@ -21,22 +25,57 @@ def get_charts(chart):
def get_charts_list():
with open("./release-manifest-image/release_manifest.yaml") as f:
manifest = yaml.safe_load(f)
manifest = yaml.load(f)
charts = {}
for chart in manifest["spec"]["components"]["workloads"]["helm"]:
charts.update(get_charts(chart))
return charts
def main():
print("Checking charts versions in release manifest")
def check_charts(fix: bool) -> bool:
success = True
charts = get_charts_list()
to_fix = {}
for chart in charts:
expected_version = get_chart_version(chart)
if expected_version != charts[chart]:
success = False
to_fix[f'%%CHART_REPO%%/%%CHART_PREFIX%%{chart}'] = expected_version
print(f"{chart}: Expected: {expected_version}, Got: {charts[chart]}")
if not success:
if fix and not success:
fix_charts(to_fix)
return True
return success
def fix_charts(to_fix):
manifest_path = pathlib.Path("./release-manifest-image/release_manifest.yaml")
manifest = yaml.load(manifest_path)
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.width = 4096
for chart_index, chart in enumerate(manifest["spec"]["components"]["workloads"]["helm"]):
changed = False
if chart["chart"] in to_fix.keys():
changed = True
chart["version"] = to_fix[chart["chart"]]
for subchart_index, subchart in enumerate(chart.get("addonCharts", [])):
if subchart["chart"] in to_fix.keys():
changed = True
subchart["version"] = to_fix[subchart["chart"]]
chart["addonCharts"][subchart_index] = subchart
for subchart_index, subchart in enumerate(chart.get("dependencyCharts", [])):
if subchart["chart"] in to_fix.keys():
changed = True
subchart["version"] = to_fix[subchart["chart"]]
chart["dependencyCharts"][subchart_index] = subchart
if changed:
manifest["spec"]["components"]["workloads"]["helm"][chart_index] = chart
yaml.dump(manifest, manifest_path)
def main():
print("Checking charts versions in release manifest")
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--check', action='store_true')
args = parser.parse_args()
if not check_charts(not args.check):
sys.exit(1)
else:
print("All local charts in release manifest are using the right version")

10
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,10 @@
repos:
- repo: local
hooks:
- id: check-manifest
name: "Check release-manifest"
entry: .obs/manifest-check.py
language: python
additional_dependencies: ['ruamel.yaml']
pass_filenames: false
always_run: true

View File

@@ -9,81 +9,81 @@ spec:
k3s:
version: v1.32.4+k3s1
coreComponents:
- name: traefik-crd
version: 34.2.1+up34.2.0
type: HelmChart
- name: traefik
version: 34.2.1+up34.2.0
type: HelmChart
- name: local-path-provisioner
containers:
- name: traefik-crd
version: 34.2.1+up34.2.0
type: HelmChart
- name: traefik
version: 34.2.1+up34.2.0
type: HelmChart
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.31
type: Deployment
- name: coredns
containers:
containers:
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.31
type: Deployment
- name: coredns
image: rancher/mirrored-coredns-coredns:1.12.1
type: Deployment
- name: metrics-server
containers:
containers:
- name: coredns
image: rancher/mirrored-coredns-coredns:1.12.1
type: Deployment
- name: metrics-server
image: rancher/mirrored-metrics-server:v0.7.2
type: Deployment
containers:
- name: metrics-server
image: rancher/mirrored-metrics-server:v0.7.2
type: Deployment
rke2:
version: v1.32.4+rke2r1
coreComponents:
- name: rke2-cilium
version: 1.17.300
type: HelmChart
- name: rke2-canal
version: v3.29.3-build2025040801
type: HelmChart
- name: rke2-calico-crd
version: v3.29.101
type: HelmChart
- name: rke2-calico
version: v3.29.300
type: HelmChart
- name: rke2-coredns
version: 1.39.201
type: HelmChart
- name: rke2-ingress-nginx
version: 4.12.101
type: HelmChart
- name: rke2-metrics-server
version: 3.12.200
type: HelmChart
- name: rancher-vsphere-csi
version: 3.3.1-rancher900
type: HelmChart
- name: rancher-vsphere-cpi
version: 1.10.000
type: HelmChart
- name: harvester-cloud-provider
version: 0.2.900
type: HelmChart
- name: harvester-csi-driver
version: 0.1.2300
type: HelmChart
- name: rke2-snapshot-controller-crd
version: 4.0.002
type: HelmChart
- name: rke2-snapshot-controller
version: 4.0.002
type: HelmChart
# Deprecated this empty chart addon can be removed in v1.34
- name: rke2-snapshot-validation-webhook
version: 0.0.0
type: HelmChart
- name: rke2-cilium
version: 1.17.300
type: HelmChart
- name: rke2-canal
version: v3.29.3-build2025040801
type: HelmChart
- name: rke2-calico-crd
version: v3.29.101
type: HelmChart
- name: rke2-calico
version: v3.29.300
type: HelmChart
- name: rke2-coredns
version: 1.39.201
type: HelmChart
- name: rke2-ingress-nginx
version: 4.12.101
type: HelmChart
- name: rke2-metrics-server
version: 3.12.200
type: HelmChart
- name: rancher-vsphere-csi
version: 3.3.1-rancher900
type: HelmChart
- name: rancher-vsphere-cpi
version: 1.10.000
type: HelmChart
- name: harvester-cloud-provider
version: 0.2.900
type: HelmChart
- name: harvester-csi-driver
version: 0.1.2300
type: HelmChart
- name: rke2-snapshot-controller-crd
version: 4.0.002
type: HelmChart
- name: rke2-snapshot-controller
version: 4.0.002
type: HelmChart
# Deprecated this empty chart addon can be removed in v1.34
- name: rke2-snapshot-validation-webhook
version: 0.0.0
type: HelmChart
operatingSystem:
version: "6.1"
zypperID: "SL-Micro"
cpeScheme: "cpe:/o:suse:sl-micro:6.1"
prettyName: "SUSE Linux Micro 6.1"
version: '6.1'
zypperID: SL-Micro
cpeScheme: cpe:/o:suse:sl-micro:6.1
prettyName: SUSE Linux Micro 6.1
supportedArchs:
- "x86_64"
- "aarch64"
- x86_64
- aarch64
workloads:
helm:
- prettyName: Rancher
@@ -106,20 +106,20 @@ spec:
repository: https://charts.rancher.io
- prettyName: MetalLB
releaseName: metallb
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%metallb"
version: "%%CHART_MAJOR%%.0.0+up0.14.9"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%metallb'
version: '%%CHART_MAJOR%%.0.0+up0.14.9'
- prettyName: CDI
releaseName: cdi
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%cdi"
version: "%%CHART_MAJOR%%.0.0+up0.5.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%cdi'
version: '%%CHART_MAJOR%%.0.0+up0.5.0'
- prettyName: KubeVirt
releaseName: kubevirt
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt"
version: "%%CHART_MAJOR%%.0.0+up0.5.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt'
version: '%%CHART_MAJOR%%.0.0+up0.5.0'
addonCharts:
- releaseName: kubevirt-dashboard-extension
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt-dashboard-extension"
version: "%%CHART_MAJOR%%.0.2+up1.3.2"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt-dashboard-extension'
version: '%%CHART_MAJOR%%.0.2+up1.3.2'
- prettyName: NeuVector
releaseName: neuvector
chart: neuvector
@@ -137,8 +137,8 @@ spec:
version: 2.1.3
- prettyName: EndpointCopierOperator
releaseName: endpoint-copier-operator
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%endpoint-copier-operator"
version: "%%CHART_MAJOR%%.0.1+up0.3.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%endpoint-copier-operator'
version: '%%CHART_MAJOR%%.0.1+up0.3.0'
- prettyName: Elemental
releaseName: elemental-operator
chart: oci://registry.suse.com/rancher/elemental-operator-chart
@@ -154,29 +154,29 @@ spec:
version: 3.0.0
- prettyName: SRIOV
releaseName: sriov-network-operator
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%sriov-network-operator"
version: "%%CHART_MAJOR%%.0.2+up1.5.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%sriov-network-operator'
version: '%%CHART_MAJOR%%.0.2+up1.5.0'
dependencyCharts:
- releaseName: sriov-crd
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%sriov-crd"
version: "%%CHART_MAJOR%%.0.2+up1.5.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%sriov-crd'
version: '%%CHART_MAJOR%%.0.2+up1.5.0'
- prettyName: Akri
releaseName: akri
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%akri"
version: "%%CHART_MAJOR%%.0.0+up0.12.20"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%akri'
version: '%%CHART_MAJOR%%.0.0+up0.12.20'
addonCharts:
- releaseName: akri-dashboard-extension
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%akri-dashboard-extension"
version: "%%CHART_MAJOR%%.0.2+up1.3.1"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%akri-dashboard-extension'
version: '%%CHART_MAJOR%%.0.2+up1.3.1'
- prettyName: Metal3
releaseName: metal3
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%metal3"
version: "%%CHART_MAJOR%%.0.10+up0.12.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%metal3'
version: '%%CHART_MAJOR%%.0.10+up0.12.0'
- prettyName: RancherTurtles
releaseName: rancher-turtles
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles"
version: "%%CHART_MAJOR%%.0.4+up0.20.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles'
version: '%%CHART_MAJOR%%.0.4+up0.20.0'
- prettyName: RancherTurtlesAirgapResources
releaseName: rancher-turtles-airgap-resources
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles-airgap-resources"
version: "%%CHART_MAJOR%%.0.4+up0.20.0"
chart: '%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles-airgap-resources'
version: '%%CHART_MAJOR%%.0.4+up0.20.0'