Skip to content

Commit 124b1ca

Browse files
committed
Add rebase_flannel script to update flannel images
1 parent c90956d commit 124b1ca

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

Diff for: scripts/auto-rebase/rebase.py

+17
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ def run_rebase_ai_model_serving_sh(release):
102102
return RebaseScriptResult(success=result.returncode == 0, output=result.stdout)
103103

104104

105+
def run_rebase_flannel():
106+
"""Run the 'rebase_flannel.sh' script and return the script's output."""
107+
script_dir = os.path.abspath(os.path.dirname(__file__))
108+
args = [f"{script_dir}/rebase_flannel.sh"]
109+
logging.info(f"Running: '{' '.join(args)}'")
110+
start = timer()
111+
result = subprocess.run(
112+
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, check=False)
113+
logging.info(f"Return code: {result.returncode}. Output:\n" +
114+
"==================================================\n" +
115+
f"{result.stdout}" +
116+
"==================================================\n")
117+
end = timer() - start
118+
logging.info(f"Script returned code: {result.returncode}. It ran for {end/60:.0f}m{end%60:.0f}s.")
119+
return RebaseScriptResult(success=result.returncode == 0, output=result.stdout)
120+
121+
105122
def commit_str(commit):
106123
"""Returns the first 8 characters of the commit's SHA hash and the commit summary."""
107124
return f"{commit.hexsha[:8]} - {commit.summary}"

Diff for: scripts/auto-rebase/rebase_flannel.sh

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o errtrace
5+
set -o nounset
6+
set -o pipefail
7+
8+
shopt -s expand_aliases
9+
shopt -s extglob
10+
11+
export PS4='+ $(date "+%T.%N") ${BASH_SOURCE#$HOME/}:$LINENO \011'
12+
13+
REPOROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/../..")"
14+
STAGING_DIR="${REPOROOT}/_output/staging"
15+
FLANNEL_VERSION=v0.25.6
16+
FLANNEL_CNI_PLUGIN_VERSION=v1.5.1-flannel2
17+
REGISTRY="docker.io/flannel"
18+
declare -A GOARCH_TO_UNAME_MAP=( ["amd64"]="x86_64" ["arm64"]="aarch64" )
19+
declare -A FLANNEL_MAP=( ["flannel"]="flannel_release.json" ["flannel-plugin"]="flannel-plugin_release.json")
20+
21+
title() {
22+
echo -e "\E[34m$1\E[00m";
23+
}
24+
25+
get_manifest_from_docker() {
26+
title "Downloading manifest for flannel"
27+
mkdir -p "${STAGING_DIR}"
28+
pushd "${STAGING_DIR}" >/dev/null
29+
oc image info ${REGISTRY}/flannel:${FLANNEL_VERSION} --show-multiarch -ojson > "${FLANNEL_MAP["flannel"]}"
30+
oc image info ${REGISTRY}/flannel-cni-plugin:${FLANNEL_CNI_PLUGIN_VERSION} --show-multiarch -ojson > "${FLANNEL_MAP["flannel-plugin"]}"
31+
popd >/dev/null
32+
}
33+
34+
35+
update_flannel_images() {
36+
title "Rebasing flannel images"
37+
38+
for goarch in amd64 arm64; do
39+
arch=${GOARCH_TO_UNAME_MAP["${goarch}"]:-noarch}
40+
41+
local kustomization_arch_file="${REPOROOT}/assets/optional/flannel/kustomization.${arch}.yaml"
42+
local flannel_release_json="${REPOROOT}/assets/optional/flannel/release-flannel-${arch}.json"
43+
44+
jq -n "{\"release\": {\"base\": \"${REGISTRY}\"}, \"images\": {}}" > "${flannel_release_json}"
45+
46+
# Create extra kustomization for each arch in separate file.
47+
# Right file (depending on arch) should be appended during rpmbuild to kustomization.yaml.
48+
cat <<EOF > "${kustomization_arch_file}"
49+
50+
images:
51+
EOF
52+
53+
for container in flannel flannel-plugin; do
54+
new_image_name=$(jq -r ".[] | select(.config.architecture == \"${goarch}\") | .name" "${STAGING_DIR}/${FLANNEL_MAP[${container}]}")
55+
new_image_digest=$(jq -r ".[] | select(.config.architecture == \"${goarch}\") | .digest" "${STAGING_DIR}/${FLANNEL_MAP[${container}]}")
56+
local new_image="${new_image_name%%:*}@${new_image_digest}"
57+
58+
cat <<EOF >> "${kustomization_arch_file}"
59+
- name: ${container}
60+
newName: ${new_image_name%%:*}
61+
digest: ${new_image_digest}
62+
EOF
63+
64+
yq -i -o json ".images += {\"${container}\": \"${new_image}\"}" "${flannel_release_json}"
65+
done # for container
66+
done # for goarch
67+
}
68+
69+
get_manifest_from_docker
70+
update_flannel_images

0 commit comments

Comments
 (0)