Skip to content

Commit

Permalink
Added updatecli to update Flannel chart
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bonafiglia <[email protected]>
  • Loading branch information
rbrtbnfgl committed Apr 16, 2024
1 parent 60cd746 commit 0e3ee14
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
24 changes: 24 additions & 0 deletions updatecli/scripts/update-flannel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
if [ -n "$FLANNEL_VERSION" ]; then
app_version=$(echo "$FLANNEL_VERSION" | grep -Eo 'v[0-9]+.[0-9]+.[0-9+]')
current_flannel_version=$(sed -nr 's/^\+ tag: ('v[0-9]+.[0-9]+.[0-9+]')/\1/p' packages/rke2-flannel/generated-changes/patch/values.yaml.patch | head -1)
current_app_version=$(echo "$current_flannel_version" | grep -Eo 'v[0-9]+.[0-9]+.[0-9+]')
if [ "$current_flannel_version" != "$FLANNEL_VERSION" ]; then
echo "Updating Flannel chart to $FLANNEL_VERSION"
if [ "$app_version" != "$current_app_version" ]; then
sed -i "s/ version: .*/ version: $app_version/g" packages/rke2-flannel/generated-changes/patch/Chart.yaml.patch
sed -i "s/- tag: $current_app_version/- tag: $app_version/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch
sed -i "s/+ tag: $current_flannel_version/+ tag: $FLANNEL_VERSION/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch
yq -i ".url = \"https://github.com/flannel-io/flannel/releases/download/$app_version/flannel.tgz\" |
.packageVersion = 00" packages/rke2-flannel/package.yaml
else
sed -i "s/+ tag: $current_flannel_version/+ tag: $FLANNEL_VERSION/g" packages/rke2-flannel/generated-changes/patch/values.yaml.patch
package_version=$(yq '.packageVersion' packages/rke2-flannel/package.yaml)
new_version=$(printf "%02d" $(($package_version + 1)))
yq -i ".packageVersion = $new_version" packages/rke2-flannel/package.yaml
fi
GOCACHE='/home/runner/.cache/go-build' GOPATH='/home/runner/go' PACKAGE='rke2-flannel' make prepare
GOCACHE='/home/runner/.cache/go-build' GOPATH='/home/runner/go' PACKAGE='rke2-flannel' make patch
make clean
fi
fi
58 changes: 58 additions & 0 deletions updatecli/updatecli.d/updateflannel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: "Update Flannel version"

sources:
flannel:
name: Get flannel version
kind: githubrelease
spec:
owner: rancher
repository: image-build-flannel
token: '{{ requiredEnv .github.token }}'
username: '{{ requiredEnv .github.username }}'
typefilter:
latest: true
release: true
draft: false
prerelease: false
versionfilter:
kind: regex
# pattern accepts any semver constraint
pattern: "v[0-9]+.[0-9]+.[0-9]+-build[0-9]+"

targets:
flannelImage:
name: "Bump to latest flannel version on the chart"
kind: shell
scmid: default
sourceid: flannel
spec:
command: 'updatecli/scripts/update-flannel.sh'
environments:
- name: FLANNEL_VERSION
value: '{{ source "flannel" }}'


scms:
default:
kind: github
spec:
token: '{{ requiredEnv .github.token }}'
username: '{{ requiredEnv .github.username }}'
user: '{{ .github.username }}'
email: '{{ .github.email }}'
owner: '{{ .github.owner }}'
repository: '{{ .github.repository }}'
branch: '{{ .github.branch }}'

actions:
default:
title: 'Update Flannel version to {{ source "flannel" }}'
kind: github/pullrequest
spec:
automerge: false
labels:
- chore
- skip-changelog
- status/auto-created
scmid: default

0 comments on commit 0e3ee14

Please sign in to comment.