Skip to content

Commit 192e332

Browse files
tico24yu-croco
andauthored
feat(argo-events): Script to update the Argo Events CRDs (#3784)
Signed-off-by: Tim Collins <tim@thecollins.team> Signed-off-by: Tim Collins <45351296+tico24@users.noreply.github.com> Co-authored-by: Aikawa <yu.croco@gmail.com>
1 parent cdda6f8 commit 192e332

File tree

5 files changed

+162
-2
lines changed

5 files changed

+162
-2
lines changed

charts/argo-events/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v1.9.10
33
description: A Helm chart for Argo Events, the event-driven workflow automation framework
44
name: argo-events
5-
version: 2.4.20
5+
version: 2.4.21
66
home: https://github.com/argoproj/argo-helm
77
icon: https://avatars.githubusercontent.com/u/30269780?s=200&v=4
88
keywords:
@@ -19,4 +19,4 @@ annotations:
1919
url: https://argoproj.github.io/argo-helm/pgp_keys.asc
2020
artifacthub.io/changes: |
2121
- kind: changed
22-
description: Bump argo-events to v1.9.10
22+
description: Rename CRD files to match upstream. The contents are unchanged.

charts/argo-events/templates/crds/eventsource-crd.yml renamed to charts/argo-events/templates/crds/eventsources-crd.yml

File renamed without changes.
File renamed without changes.

scripts/renovate-bump-version.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ if [[ "$dependency_name" == "argo-workflows" ]]; then
4545
"$(dirname "$0")/update-argo-workflows-crds.sh" "$dependency_version"
4646
fi
4747

48+
# If the dependency is argo-events, also update CRDs
49+
if [[ "$dependency_name" == "argo-events" ]]; then
50+
"$(dirname "$0")/update-argo-events-crds.sh" "$dependency_version"
51+
4852
# If the dependency is argo-rollouts, also update CRDs
4953
if [[ "$dependency_name" == "argo-rollouts" ]]; then
5054
"$(dirname "$0")/update-argo-rollouts-crds.sh" "$dependency_version"
55+
5156
# If the dependency is argo-cd, also update CRDs
5257
if [[ "$dependency_name" == "argo-cd" ]]; then
5358
"$(dirname "$0")/update-argo-cd-crds.sh" "$dependency_version"

scripts/update-argo-events-crds.sh

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Update Argo Events CRDs from upstream
4+
#
5+
# Usage: ./scripts/update-argo-events-crds.sh <version>
6+
# Example: ./scripts/update-argo-events-crds.sh v1.9.10
7+
#
8+
9+
set -euo pipefail
10+
11+
if ! command -v jq &> /dev/null; then
12+
echo "Error: jq is required but not installed"
13+
exit 1
14+
fi
15+
16+
VERSION="${1:-}"
17+
18+
if [[ -z "$VERSION" ]]; then
19+
echo "Usage: $0 <version>"
20+
echo "Example: $0 v1.9.10"
21+
exit 1
22+
fi
23+
24+
# Ensure version starts with 'v'
25+
if [[ ! "$VERSION" =~ ^v ]]; then
26+
VERSION="v${VERSION}"
27+
fi
28+
29+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
30+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
31+
CRD_DIR="$REPO_ROOT/charts/argo-events/templates/crds"
32+
33+
UPSTREAM_BASE_URL="https://raw.githubusercontent.com/argoproj/argo-events/${VERSION}/manifests/base/crds"
34+
35+
# Function to get CRD file list from GitHub API
36+
get_crd_files() {
37+
local api_url="https://api.github.com/repos/argoproj/argo-events/contents/manifests/base/crds?ref=${VERSION}"
38+
39+
curl -sSfL "$api_url" | jq -r '.[] | select(.name | test("^argoproj\\.io_.*\\.yaml$")) | .name'
40+
}
41+
42+
# Convert upstream filename to local template filename
43+
# e.g., "argoproj.io_eventbus.yaml" -> "eventbus-crd.yml"
44+
to_local_filename() {
45+
local upstream_name="$1"
46+
local base="${upstream_name#argoproj.io_}"
47+
echo "${base%.yaml}-crd.yml"
48+
}
49+
50+
# Process a downloaded CRD into a Helm template:
51+
# - Remove the "auto-generated" comment line
52+
# - Wrap in {{- if .Values.crds.install }} conditional
53+
# - Add helm.sh/resource-policy annotation and custom annotation support
54+
# - Ensure 'name:' comes before 'annotations:' in metadata
55+
process_crd() {
56+
local src_file="$1"
57+
local dest_file="$2"
58+
59+
{
60+
cat <<'HEADER'
61+
{{- if .Values.crds.install }}
62+
HEADER
63+
64+
# Remove leading "---" if present, then process the YAML
65+
sed '/^---$/d' "$src_file" | awk '
66+
BEGIN { state = "init"; name_line = "" }
67+
68+
# Skip auto-generated comment
69+
/^# This is an auto-generated file/ { next }
70+
71+
state == "init" && /^metadata:$/ {
72+
state = "meta"
73+
print
74+
next
75+
}
76+
77+
# In metadata, capture name line
78+
state == "meta" && /^ name:/ {
79+
name_line = $0
80+
next
81+
}
82+
83+
# Skip upstream annotations section
84+
state == "meta" && /^ annotations:$/ { state = "anno"; next }
85+
state == "anno" && /^ / { next }
86+
state == "anno" && !/^ / { state = "meta" }
87+
88+
# Skip upstream labels section
89+
state == "meta" && /^ labels:$/ { state = "labels"; next }
90+
state == "labels" && /^ / { next }
91+
state == "labels" && !/^ / { state = "meta" }
92+
93+
# End of metadata block - emit name and annotations
94+
state == "meta" && /^[^ ]/ {
95+
if (name_line != "") {
96+
print name_line
97+
}
98+
print " annotations:"
99+
print " {{- if .Values.crds.keep }}"
100+
print " \"helm.sh/resource-policy\": keep"
101+
print " {{- end }}"
102+
print " {{- with .Values.crds.annotations }}"
103+
print " {{- toYaml . | nindent 4 }}"
104+
print " {{- end }}"
105+
state = "done"
106+
}
107+
108+
# Default: print everything else
109+
{ print }
110+
'
111+
112+
echo "{{- end }}"
113+
} > "$dest_file"
114+
}
115+
116+
echo "Updating Argo Events CRDs to $VERSION"
117+
echo "======================================="
118+
119+
mkdir -p "$CRD_DIR"
120+
121+
# Clean existing CRD files before downloading in case upstream have deleted a CRD
122+
rm -f "$CRD_DIR"/*-crd.yml
123+
124+
# Get file list dynamically from GitHub API
125+
crd_files=$(get_crd_files)
126+
127+
if [[ -z "$crd_files" ]]; then
128+
echo " Error: Failed to fetch CRD file list"
129+
exit 1
130+
fi
131+
132+
TMP_DIR=$(mktemp -d)
133+
trap 'rm -rf "$TMP_DIR"' EXIT
134+
135+
while IFS= read -r crd_file; do
136+
local_name=$(to_local_filename "$crd_file")
137+
url="$UPSTREAM_BASE_URL/$crd_file"
138+
tmp_file="$TMP_DIR/$crd_file"
139+
dest="$CRD_DIR/$local_name"
140+
141+
echo " Downloading $crd_file -> $local_name..."
142+
if ! curl -sSfL "$url" -o "$tmp_file"; then
143+
echo " Warning: Failed to download $crd_file"
144+
continue
145+
fi
146+
147+
process_crd "$tmp_file" "$dest"
148+
echo " Downloaded and processed $local_name"
149+
done <<< "$crd_files"
150+
151+
echo ""
152+
echo "Done! CRDs updated to $VERSION"
153+
echo ""
154+
echo "Files updated in:"
155+
echo " - $CRD_DIR/"

0 commit comments

Comments
 (0)