|
| 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