Skip to content

Commit c0b6e17

Browse files
committed
test
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
1 parent e2d1006 commit c0b6e17

File tree

5 files changed

+194
-2
lines changed

5 files changed

+194
-2
lines changed

charts/chart_versions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ charts:
2929
- version: v4.2.314
3030
filename: /charts/rke2-multus.yaml
3131
bootstrap: true
32-
- version: v0.28.101
32+
- version: v0.28.000
3333
filename: /charts/rke2-flannel.yaml
3434
bootstrap: true
3535
- version: 1.13.000

scripts/build-images

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ xargs -n1 -t $PULL_CMD << EOF > build/images-harvester.txt
111111
EOF
112112

113113
xargs -n1 -t $PULL_CMD << EOF > build/images-flannel.txt
114-
${REGISTRY}/rancher/hardened-flannel:v0.28.1-build20260206
114+
${REGISTRY}/rancher/hardened-flannel:v0.28.0-build20260206
115115
${REGISTRY}/rancher/hardened-cni-plugins:v1.9.0-build20260206
116116
EOF
117117
fi

updatecli/scripts/create-issue.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
GITHUB_REPOSITORY="rbrtbnfgl/rke2"
4+
5+
6+
create-issue() {
7+
chart_version=$?
8+
gh extension install valeriobelli/gh-milestone
9+
10+
MILESTONES_JSON=$(gh milestone list --state open --json dueOn,title)
11+
12+
TODAY=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
13+
14+
TARGET_MILESTONE=$(echo "$MILESTONES_JSON" | jq -r --arg today "$TODAY" '
15+
[ .[] | select(.title | contains("Release Cycle")) | select(.dueOn >= $today) ]
16+
| sort_by(.dueOn)
17+
| .[0].title
18+
')
19+
20+
if [ "$TARGET_MILESTONE" == "null" ] || [ -z "$TARGET_MILESTONE" ]; then
21+
echo "No unexpired Release Cycle milestone found."
22+
exit 1
23+
fi
24+
25+
echo "Selected Milestone: $TARGET_MILESTONE"
26+
ISSUE_TITLE="Update CNIs for $TARGET_MILESTONE"
27+
28+
issue=$(
29+
gh issue list \
30+
--repo ${GITHUB_REPOSITORY} \
31+
--state "open" \
32+
--search "${ISSUE_TITLE}" \
33+
--json number,body
34+
)
35+
if [[ -z "$issue" ]]; then
36+
number=$(gh issue create \
37+
--title "${ISSUE_TITLE}" \
38+
--body "Update CNIs for $TARGET_MILESTONE:" \
39+
--repo ${GITHUB_REPOSITORY} \
40+
--milestone "$TARGET_MILESTONE" \
41+
--json number --jq '.number')
42+
else
43+
min_json=$(jq -s 'sort_by(.number) | .[0]' data.json)
44+
body=$(jq -s 'sort_by(.number) | .[0]' data.json | jq -r '.body')
45+
number=$(jq -s 'sort_by(.number) | .[0]' data.json | jq -r '.number')
46+
if [[ -n "$chart_version" ]]; then
47+
gh issue comment \
48+
${number} \
49+
--repo ${GITHUB_REPOSITORY} \
50+
--body "${ISSUE_BODY}"
51+
fi
52+
fi
53+
return $number
54+
}
55+
56+
export -f create-issue
57+
"$@"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
info()
4+
{
5+
echo '[INFO] ' "$@"
6+
}
7+
warn()
8+
{
9+
echo '[WARN] ' "$@" >&2
10+
}
11+
fatal()
12+
{
13+
echo '[ERROR] ' "$@" >&2
14+
exit 1
15+
}
16+
17+
update_chart_version() {
18+
info "updating chart ${1} in ${CHART_VERSIONS_FILE}"
19+
CURRENT_VERSION=$(yq -r '.charts[] | select(.filename == "/charts/'"${1}"'.yaml") | .version' ${CHART_VERSIONS_FILE})
20+
NEW_VERSION=${2}
21+
if [ "${CURRENT_VERSION}" != "${NEW_VERSION}" ]; then
22+
info "found version ${CURRENT_VERSION}, updating to ${NEW_VERSION}"
23+
chart_updated=true
24+
if test "$DRY_RUN" == "false"; then
25+
sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g" ${CHART_VERSIONS_FILE}
26+
else
27+
info "dry-run is enabled, no changes will occur"
28+
fi
29+
else
30+
info "no new version found"
31+
fi
32+
}
33+
34+
update_chart_images() {
35+
info "downloading chart ${1} version ${2} to extract image versions"
36+
tempdir=$(mktemp -d)
37+
CHART_URL="https://github.com/rancher/rke2-charts/raw/main/assets/${1}/${1}-${2}.tgz"
38+
curl -s -L -o $tempdir/${1}-${2}.tgz ${CHART_URL}
39+
if test "$chart_updated" == "true"; then
40+
# get all images and tags for the latest constraint
41+
cni=$(echo "${1}" | sed -nE 's/rke2-(.*)/\1/p')
42+
IMAGES_TAG=$(helm template $tempdir/${1}-${2}.tgz | grep -E image:)
43+
LIST_IMAGES=""
44+
while IFS= read -r line ; do
45+
IMAGE=$(echo "${line}" | sed -nE 's/image: (.*)/\1/p' | sed 's/\//\\\//g' | tr -dc '[:alnum:]:.\-/\\')
46+
LIST_IMAGES=$(echo "$LIST_IMAGES\${REGISTRY}/${IMAGE}\n")
47+
done <<< "$IMAGES_TAG"
48+
if test "$DRY_RUN" == "false"; then
49+
awk -v images_list="$LIST_IMAGES" "BEGIN{split(images_list, images_array, \"\n\"); for (i in images_array) {n = split(images_array[i], image_tag, \":\"); if (n == 2) images_list_array[image_tag[1]] = image_tag[2];}}/.*build\/images-${cni}.txt.*/ {print; getline; while (\$1 != \"EOF\") { n = split(\$1, current_image, \":\"); if (n == 2) print \" \"current_image[1]\":\"images_list_array[current_image[1]]; getline;}}; {print}" ${CHART_AIRGAP_IMAGES_FILE} > $tempdir/images_file.sh
50+
cp $tempdir/images_file.sh ${CHART_AIRGAP_IMAGES_FILE}
51+
else
52+
info "dry-run is enabled, no changes will occur"
53+
fi
54+
else
55+
info "no new version found"
56+
fi
57+
# removing downloaded artifacts
58+
rm -rf $tempdir/
59+
}
60+
61+
CHART_VERSIONS_FILE="charts/chart_versions.yaml"
62+
CHART_AIRGAP_IMAGES_FILE="scripts/build-images"
63+
64+
65+
CHART_NAME=${1}
66+
CHART_VERSION=${2}
67+
chart_updated=false
68+
69+
update_chart_version ${CHART_NAME} ${CHART_VERSION}
70+
update_chart_images ${CHART_NAME} ${CHART_VERSION}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This small test makes sure that updatecli is working properly on a repo.
2+
# To test this:
3+
# have "UPDATECLI_GITHUB_ACTOR" env set to your github username
4+
# have "UPDATECLI_GITHUB_TOKEN" env set to your github token
5+
# have the latest version of updatecli installed
6+
# 'updatecli diff -v updatecli/values.yaml -c updatecli/updatecli.d/vsphere-cpi.yml'
7+
# In the future, more useful files should be added to this directory.
8+
---
9+
name: "Update flannel charts and images"
10+
# Make sure we can pull in github repos from multiple orgs
11+
scms:
12+
rke2:
13+
kind: "github"
14+
spec:
15+
user: "{{ .github.user }}"
16+
email: "{{ .github.email }}"
17+
username: "{{ requiredEnv .github.username }}"
18+
token: '{{ requiredEnv .github.token }}'
19+
owner: rbrtbnfgl
20+
repository: rke2
21+
branch: master
22+
23+
sources:
24+
flannel:
25+
name: "Get flannel chart version"
26+
kind: "helmchart"
27+
spec:
28+
url: https://rancher.github.io/rke2-charts
29+
name: rke2-flannel
30+
versionfilter:
31+
kind: "latest"
32+
issue:
33+
name: "Get issue number"
34+
kind: "shell"
35+
spec:
36+
command: bash -c "./updatecli/scripts/create-issue.sh create-issue"
37+
38+
conditions:
39+
flannelVersionShouldBeUpdated:
40+
name: "Check if flannel chart should be updated or not"
41+
kind: shell
42+
sourceid: flannel
43+
spec:
44+
command: bash ./updatecli/scripts/validate_version.sh rke2-flannel
45+
46+
targets:
47+
flannelCNI:
48+
name: "Update the flannel airgap images"
49+
kind: "shell"
50+
scmid: "rke2"
51+
sourceid: flannel
52+
spec:
53+
command: bash ./updatecli/scripts/update_chart_and_images_cni.sh rke2-flannel
54+
55+
actions:
56+
github:
57+
kind: "github/pullrequest"
58+
scmid: "rke2"
59+
spec:
60+
automerge: false
61+
draft: false
62+
mergemethod: squash
63+
parent: false
64+
title: 'Update flannel chart to {{ source "flannel" }}'
65+
description: 'This is an automated PR to update Helm chart versions. issue #{{ source "issue" }}'

0 commit comments

Comments
 (0)