-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add updatecli configuration to update vsphere cpi and csi charts #5326
Merged
galal-hussein
merged 3 commits into
rancher:master
from
galal-hussein:automatic_update_for_vsphere_charts
Jul 16, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
info() | ||
{ | ||
echo '[INFO] ' "$@" | ||
} | ||
warn() | ||
{ | ||
echo '[WARN] ' "$@" >&2 | ||
} | ||
fatal() | ||
{ | ||
echo '[ERROR] ' "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
update_chart_version() { | ||
info "updating chart ${1} in ${CHART_VERSIONS_FILE}" | ||
CURRENT_VERSION=$(yq -r '.charts[] | select(.filename == "/charts/'"${1}"'.yaml") | .version' ${CHART_VERSIONS_FILE}) | ||
NEW_VERSION=${2} | ||
if [ "${CURRENT_VERSION}" != "${NEW_VERSION}" ]; then | ||
info "found version ${CURRENT_VERSION}, updating to ${NEW_VERSION}" | ||
chart_updated=true | ||
if test "$DRY_RUN" == "false"; then | ||
sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g" ${CHART_VERSIONS_FILE} | ||
else | ||
info "dry-run is enabled, no changes will occur" | ||
fi | ||
else | ||
info "no new version found" | ||
fi | ||
} | ||
|
||
update_chart_images() { | ||
info "downloading chart ${1} version ${2} to extract image versions" | ||
CHART_URL="https://github.com/rancher/rke2-charts/raw/main/assets/${1}/${1}-${2}.tgz" | ||
curl -s -L ${CHART_URL} | tar xzv ${1}/values.yaml 1> /dev/null | ||
if test "$chart_updated" == "true"; then | ||
# get all images and tags for the latest constraint | ||
IMAGES_TAG=$(yq -y -r '.versionOverrides[] | select( .constraint == "~ 1.27" or .constraint == ">= 1.24 < 1.28") | .values' ${1}/values.yaml | grep -E "repo|tag") | ||
while IFS= read -r line ; do | ||
if grep "repo" <<< ${line} &> /dev/null; then | ||
image=${line#*: } | ||
tag_line=$(echo "${IMAGES_TAG}" | grep -A1 ${image} 2>&1| sed -n '2 p' | tr -d " ") | ||
tag=${tag_line#*:} | ||
target_image=$(grep ${image} ${CHART_AIRGAP_IMAGES_FILE}) | ||
if [ -z "${target_image}" ]; then | ||
fatal "image ${image} not found in the airgap scripts" | ||
fi | ||
target_tag=${target_image#*:} | ||
if [ "$target_tag" != "${tag}" ]; then | ||
info updating image ${image} in airgap script from version ${target_tag} to ${tag} | ||
if test "$DRY_RUN" == "false"; then | ||
sed -r -i 's~(.*'${image}':).*~\1'${tag}'~g' ${CHART_AIRGAP_IMAGES_FILE} | ||
else | ||
info "dry-run is enabled, no changes will occur" | ||
fi | ||
else | ||
info "image ${image} did not update from version ${tag}" | ||
fi | ||
else | ||
continue | ||
fi | ||
done <<< "$IMAGES_TAG" | ||
else | ||
info "no new version found" | ||
fi | ||
# removing downloaded artifacts | ||
rm -rf ${1}/ | ||
} | ||
|
||
CHART_VERSIONS_FILE="charts/chart_versions.yaml" | ||
CHART_AIRGAP_IMAGES_FILE="scripts/build-images" | ||
|
||
|
||
CHART_NAME=${1} | ||
CHART_VERSION=${2} | ||
chart_updated=false | ||
|
||
update_chart_version ${CHART_NAME} ${CHART_VERSION} | ||
update_chart_images ${CHART_NAME} ${CHART_VERSION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
info() | ||
{ | ||
echo '[INFO] ' "$@" | ||
} | ||
warn() | ||
{ | ||
echo '[WARN] ' "$@" >&2 | ||
} | ||
fatal() | ||
{ | ||
echo '[ERROR] ' "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
|
||
CHART_VERSIONS_FILE="charts/chart_versions.yaml" | ||
|
||
|
||
CHART_NAME=${1} | ||
CHART_VERSION=${2} | ||
|
||
CURRENT_VERSION=$(yq -r '.charts[] | select(.filename == "/charts/'"${1}"'.yaml") | .version' ${CHART_VERSIONS_FILE}) | ||
if [ "${CURRENT_VERSION}" != "${CHART_VERSION}" ]; then | ||
info "chart ${CHART_NAME} should be updated from version ${CURRENT_VERSION} to ${CHART_VERSION}" | ||
exit 0 | ||
fi | ||
fatal "chart ${CHART_NAME} has the latest version" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This small test makes sure that updatecli is working properly on a repo. | ||
# To test this: | ||
# have "UPDATECLI_GITHUB_ACTOR" env set to your github username | ||
# have "UPDATECLI_GITHUB_TOKEN" env set to your github token | ||
# have the latest version of updatecli installed | ||
# 'updatecli diff -v updatecli/values.yaml -c updatecli/updatecli.d/vsphere-cpi.yml' | ||
# In the future, more useful files should be added to this directory. | ||
--- | ||
name: "Update vsphere csi/cpi charts and images" | ||
# Make sure we can pull in github repos from multiple orgs | ||
scms: | ||
rke2: | ||
kind: "github" | ||
spec: | ||
user: "{{ .github.user }}" | ||
email: "{{ .github.email }}" | ||
username: "{{ requiredEnv .github.username }}" | ||
token: '{{ requiredEnv .github.token }}' | ||
owner: rancher | ||
repository: rke2 | ||
branch: master | ||
|
||
sources: | ||
vsphere-cpi: | ||
name: "Get vsphere-cpi chart version" | ||
kind: "helmchart" | ||
spec: | ||
url: https://rancher.github.io/rke2-charts | ||
name: rancher-vsphere-cpi | ||
versionfilter: | ||
kind: "latest" | ||
|
||
conditions: | ||
vsphereCPIVersionShouldBeUpdated: | ||
name: "Check if vsphere-cpi chart should be updated or not" | ||
kind: shell | ||
sourceid: vsphere-cpi | ||
spec: | ||
command: bash ./updatecli/scripts/validate_version.sh rancher-vsphere-cpi | ||
|
||
targets: | ||
updateVsphereCPI: | ||
name: "Update the vsphere-cpi airgap images" | ||
kind: "shell" | ||
scmid: "rke2" | ||
sourceid: vsphere-cpi | ||
spec: | ||
command: bash ./updatecli/scripts/update_chart_and_images.sh rancher-vsphere-cpi | ||
|
||
actions: | ||
github: | ||
kind: "github/pullrequest" | ||
scmid: "rke2" | ||
spec: | ||
automerge: false | ||
draft: false | ||
mergemethod: squash | ||
parent: false | ||
title: "Update vsphere-cpi chart" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This small test makes sure that updatecli is working properly on a repo. | ||
# To test this: | ||
# have "UPDATECLI_GITHUB_ACTOR" env set to your github username | ||
# have "UPDATECLI_GITHUB_TOKEN" env set to your github token | ||
# have the latest version of updatecli installed | ||
# 'updatecli diff -v updatecli/values.yaml -c updatecli/updatecli.d/vsphere-csi.yml' | ||
# In the future, more useful files should be added to this directory. | ||
--- | ||
name: "Update vsphere csi/cpi charts and images" | ||
# Make sure we can pull in github repos from multiple orgs | ||
scms: | ||
rke2: | ||
kind: "github" | ||
spec: | ||
user: "{{ .github.user }}" | ||
email: "{{ .github.email }}" | ||
username: "{{ requiredEnv .github.username }}" | ||
token: '{{ requiredEnv .github.token }}' | ||
owner: rancher | ||
repository: rke2 | ||
branch: master | ||
|
||
sources: | ||
vsphere-csi: | ||
name: "Get vsphere-csi chart version" | ||
kind: "helmchart" | ||
spec: | ||
url: https://rancher.github.io/rke2-charts | ||
name: rancher-vsphere-csi | ||
versionfilter: | ||
kind: "latest" | ||
|
||
conditions: | ||
vsphereCSIVersionShouldBeUpdated: | ||
name: "Check if vsphere-csi chart should be updated or not" | ||
kind: shell | ||
sourceid: vsphere-csi | ||
spec: | ||
command: bash ./updatecli/scripts/validate_version.sh rancher-vsphere-csi | ||
|
||
targets: | ||
updateVsphereCSI: | ||
name: "Update the vsphere-csi airgap images" | ||
kind: "shell" | ||
scmid: "rke2" | ||
sourceid: vsphere-csi | ||
spec: | ||
command: bash ./updatecli/scripts/update_chart_and_images.sh rancher-vsphere-csi | ||
|
||
actions: | ||
github: | ||
kind: "github/pullrequest" | ||
scmid: "rke2" | ||
spec: | ||
automerge: false | ||
draft: false | ||
mergemethod: squash | ||
parent: false | ||
title: "Update vsphere-csi chart" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work for you? I had problems when using the token from values.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works locally with updatecli and I used act as well to test the workflow, it seems to be working fine