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' object-format: 'sha256'
- name: Setup dependencies - name: Setup dependencies
run: | run: |
zypper in -y python3-PyYAML zypper in -y python3-ruamel.yaml
- name: Check release manifest - name: Check release manifest
run: | 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 #!/usr/bin/python3
import yaml import ruamel.yaml
import pathlib
import argparse
import sys import sys
yaml = ruamel.yaml.YAML()
def get_chart_version(chart_name: str) -> str: def get_chart_version(chart_name: str) -> str:
with open(f"./{chart_name}-chart/Chart.yaml") as f: 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"] return chart["version"]
def get_charts(chart): def get_charts(chart):
@@ -21,22 +25,57 @@ def get_charts(chart):
def get_charts_list(): def get_charts_list():
with open("./release-manifest-image/release_manifest.yaml") as f: with open("./release-manifest-image/release_manifest.yaml") as f:
manifest = yaml.safe_load(f) manifest = yaml.load(f)
charts = {} charts = {}
for chart in manifest["spec"]["components"]["workloads"]["helm"]: for chart in manifest["spec"]["components"]["workloads"]["helm"]:
charts.update(get_charts(chart)) charts.update(get_charts(chart))
return charts return charts
def main(): def check_charts(fix: bool) -> bool:
print("Checking charts versions in release manifest")
success = True success = True
charts = get_charts_list() charts = get_charts_list()
to_fix = {}
for chart in charts: for chart in charts:
expected_version = get_chart_version(chart) expected_version = get_chart_version(chart)
if expected_version != charts[chart]: if expected_version != charts[chart]:
success = False success = False
to_fix[f'%%CHART_REPO%%/%%CHART_PREFIX%%{chart}'] = expected_version
print(f"{chart}: Expected: {expected_version}, Got: {charts[chart]}") 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) sys.exit(1)
else: else:
print("All local charts in release manifest are using the right version") 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: k3s:
version: v1.32.4+k3s1 version: v1.32.4+k3s1
coreComponents: coreComponents:
- name: traefik-crd - name: traefik-crd
version: 34.2.1+up34.2.0 version: 34.2.1+up34.2.0
type: HelmChart type: HelmChart
- name: traefik - name: traefik
version: 34.2.1+up34.2.0 version: 34.2.1+up34.2.0
type: HelmChart type: HelmChart
- name: local-path-provisioner
containers:
- name: local-path-provisioner - name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.31 containers:
type: Deployment - name: local-path-provisioner
- name: coredns image: rancher/local-path-provisioner:v0.0.31
containers: type: Deployment
- name: coredns - name: coredns
image: rancher/mirrored-coredns-coredns:1.12.1 containers:
type: Deployment - name: coredns
- name: metrics-server image: rancher/mirrored-coredns-coredns:1.12.1
containers: type: Deployment
- name: metrics-server - name: metrics-server
image: rancher/mirrored-metrics-server:v0.7.2 containers:
type: Deployment - name: metrics-server
image: rancher/mirrored-metrics-server:v0.7.2
type: Deployment
rke2: rke2:
version: v1.32.4+rke2r1 version: v1.32.4+rke2r1
coreComponents: coreComponents:
- name: rke2-cilium - name: rke2-cilium
version: 1.17.300 version: 1.17.300
type: HelmChart type: HelmChart
- name: rke2-canal - name: rke2-canal
version: v3.29.3-build2025040801 version: v3.29.3-build2025040801
type: HelmChart type: HelmChart
- name: rke2-calico-crd - name: rke2-calico-crd
version: v3.29.101 version: v3.29.101
type: HelmChart type: HelmChart
- name: rke2-calico - name: rke2-calico
version: v3.29.300 version: v3.29.300
type: HelmChart type: HelmChart
- name: rke2-coredns - name: rke2-coredns
version: 1.39.201 version: 1.39.201
type: HelmChart type: HelmChart
- name: rke2-ingress-nginx - name: rke2-ingress-nginx
version: 4.12.101 version: 4.12.101
type: HelmChart type: HelmChart
- name: rke2-metrics-server - name: rke2-metrics-server
version: 3.12.200 version: 3.12.200
type: HelmChart type: HelmChart
- name: rancher-vsphere-csi - name: rancher-vsphere-csi
version: 3.3.1-rancher900 version: 3.3.1-rancher900
type: HelmChart type: HelmChart
- name: rancher-vsphere-cpi - name: rancher-vsphere-cpi
version: 1.10.000 version: 1.10.000
type: HelmChart type: HelmChart
- name: harvester-cloud-provider - name: harvester-cloud-provider
version: 0.2.900 version: 0.2.900
type: HelmChart type: HelmChart
- name: harvester-csi-driver - name: harvester-csi-driver
version: 0.1.2300 version: 0.1.2300
type: HelmChart type: HelmChart
- name: rke2-snapshot-controller-crd - name: rke2-snapshot-controller-crd
version: 4.0.002 version: 4.0.002
type: HelmChart type: HelmChart
- name: rke2-snapshot-controller - name: rke2-snapshot-controller
version: 4.0.002 version: 4.0.002
type: HelmChart type: HelmChart
# Deprecated this empty chart addon can be removed in v1.34 # Deprecated this empty chart addon can be removed in v1.34
- name: rke2-snapshot-validation-webhook - name: rke2-snapshot-validation-webhook
version: 0.0.0 version: 0.0.0
type: HelmChart type: HelmChart
operatingSystem: operatingSystem:
version: "6.1" version: '6.1'
zypperID: "SL-Micro" zypperID: SL-Micro
cpeScheme: "cpe:/o:suse:sl-micro:6.1" cpeScheme: cpe:/o:suse:sl-micro:6.1
prettyName: "SUSE Linux Micro 6.1" prettyName: SUSE Linux Micro 6.1
supportedArchs: supportedArchs:
- "x86_64" - x86_64
- "aarch64" - aarch64
workloads: workloads:
helm: helm:
- prettyName: Rancher - prettyName: Rancher
@@ -106,20 +106,20 @@ spec:
repository: https://charts.rancher.io repository: https://charts.rancher.io
- prettyName: MetalLB - prettyName: MetalLB
releaseName: metallb releaseName: metallb
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%metallb" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%metallb'
version: "%%CHART_MAJOR%%.0.0+up0.14.9" version: '%%CHART_MAJOR%%.0.0+up0.14.9'
- prettyName: CDI - prettyName: CDI
releaseName: cdi releaseName: cdi
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%cdi" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%cdi'
version: "%%CHART_MAJOR%%.0.0+up0.5.0" version: '%%CHART_MAJOR%%.0.0+up0.5.0'
- prettyName: KubeVirt - prettyName: KubeVirt
releaseName: kubevirt releaseName: kubevirt
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt'
version: "%%CHART_MAJOR%%.0.0+up0.5.0" version: '%%CHART_MAJOR%%.0.0+up0.5.0'
addonCharts: addonCharts:
- releaseName: kubevirt-dashboard-extension - releaseName: kubevirt-dashboard-extension
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt-dashboard-extension" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%kubevirt-dashboard-extension'
version: "%%CHART_MAJOR%%.0.2+up1.3.2" version: '%%CHART_MAJOR%%.0.2+up1.3.2'
- prettyName: NeuVector - prettyName: NeuVector
releaseName: neuvector releaseName: neuvector
chart: neuvector chart: neuvector
@@ -137,8 +137,8 @@ spec:
version: 2.1.3 version: 2.1.3
- prettyName: EndpointCopierOperator - prettyName: EndpointCopierOperator
releaseName: endpoint-copier-operator releaseName: endpoint-copier-operator
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%endpoint-copier-operator" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%endpoint-copier-operator'
version: "%%CHART_MAJOR%%.0.1+up0.3.0" version: '%%CHART_MAJOR%%.0.1+up0.3.0'
- prettyName: Elemental - prettyName: Elemental
releaseName: elemental-operator releaseName: elemental-operator
chart: oci://registry.suse.com/rancher/elemental-operator-chart chart: oci://registry.suse.com/rancher/elemental-operator-chart
@@ -154,29 +154,29 @@ spec:
version: 3.0.0 version: 3.0.0
- prettyName: SRIOV - prettyName: SRIOV
releaseName: sriov-network-operator releaseName: sriov-network-operator
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%sriov-network-operator" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%sriov-network-operator'
version: "%%CHART_MAJOR%%.0.2+up1.5.0" version: '%%CHART_MAJOR%%.0.2+up1.5.0'
dependencyCharts: dependencyCharts:
- releaseName: sriov-crd - releaseName: sriov-crd
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%sriov-crd" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%sriov-crd'
version: "%%CHART_MAJOR%%.0.2+up1.5.0" version: '%%CHART_MAJOR%%.0.2+up1.5.0'
- prettyName: Akri - prettyName: Akri
releaseName: akri releaseName: akri
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%akri" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%akri'
version: "%%CHART_MAJOR%%.0.0+up0.12.20" version: '%%CHART_MAJOR%%.0.0+up0.12.20'
addonCharts: addonCharts:
- releaseName: akri-dashboard-extension - releaseName: akri-dashboard-extension
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%akri-dashboard-extension" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%akri-dashboard-extension'
version: "%%CHART_MAJOR%%.0.2+up1.3.1" version: '%%CHART_MAJOR%%.0.2+up1.3.1'
- prettyName: Metal3 - prettyName: Metal3
releaseName: metal3 releaseName: metal3
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%metal3" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%metal3'
version: "%%CHART_MAJOR%%.0.10+up0.12.0" version: '%%CHART_MAJOR%%.0.10+up0.12.0'
- prettyName: RancherTurtles - prettyName: RancherTurtles
releaseName: rancher-turtles releaseName: rancher-turtles
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles'
version: "%%CHART_MAJOR%%.0.4+up0.20.0" version: '%%CHART_MAJOR%%.0.4+up0.20.0'
- prettyName: RancherTurtlesAirgapResources - prettyName: RancherTurtlesAirgapResources
releaseName: rancher-turtles-airgap-resources releaseName: rancher-turtles-airgap-resources
chart: "%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles-airgap-resources" chart: '%%CHART_REPO%%/%%CHART_PREFIX%%rancher-turtles-airgap-resources'
version: "%%CHART_MAJOR%%.0.4+up0.20.0" version: '%%CHART_MAJOR%%.0.4+up0.20.0'