Skip to content

USHIFT-5531: Auto-rebase procedure with flannel and kube-proxy image update #4726

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions scripts/auto-rebase/rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ def run_rebase_ai_model_serving_sh(release):
return RebaseScriptResult(success=result.returncode == 0, output=result.stdout)


def run_rebase_flannel():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function be executed?
I recall that newest flannel requires a kernel module, should we even proceed with this PR?

"""Run the 'rebase_flannel.sh' script and return the script's output."""
script_dir = os.path.abspath(os.path.dirname(__file__))
args = [f"{script_dir}/rebase_flannel.sh"]
logging.info(f"Running: '{' '.join(args)}'")
start = timer()
result = subprocess.run(
args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, check=False)
logging.info(f"Return code: {result.returncode}. Output:\n" +
"==================================================\n" +
f"{result.stdout}" +
"==================================================\n")
end = timer() - start
logging.info(f"Script returned code: {result.returncode}. It ran for {end/60:.0f}m{end%60:.0f}s.")
return RebaseScriptResult(success=result.returncode == 0, output=result.stdout)


def commit_str(commit):
"""Returns the first 8 characters of the commit's SHA hash and the commit summary."""
return f"{commit.hexsha[:8]} - {commit.summary}"
Expand Down
39 changes: 39 additions & 0 deletions scripts/auto-rebase/rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ EOF

update_olm_images
update_multus_images
update_kubeproxy_images

popd >/dev/null
}
Expand Down Expand Up @@ -1118,6 +1119,44 @@ EOF
done # for goarch
}

update_kubeproxy_images() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what's the difference between kube-proxy and kube-rbac-proxy? Can they be used interchangeably?

title "Rebasing kube-proxy images"

for goarch in amd64 arm64; do
arch=${GOARCH_TO_UNAME_MAP["${goarch}"]:-noarch}

local release_file="${STAGING_DIR}/release_${goarch}.json"
local kustomization_arch_file="${REPOROOT}/assets/optional/kube-proxy/kustomization.${arch}.yaml"
local kubeproxy_release_json="${REPOROOT}/assets/optional/kube-proxy/release-kube-proxy-${arch}.json"

local base_release
base_release=$(jq -r ".metadata.version" "${release_file}")
jq -n "{\"release\": {\"base\": \"$base_release\"}, \"images\": {}}" > "${kubeproxy_release_json}"

# Create extra kustomization for each arch in separate file.
# Right file (depending on arch) should be appended during rpmbuild to kustomization.yaml.
cat <<EOF > "${kustomization_arch_file}"

images:
EOF

for container in kube-proxy; do
local new_image
new_image=$(jq -r ".references.spec.tags[] | select(.name == \"${container}\") | .from.name" "${release_file}")
local new_image_name="${new_image%@*}"
local new_image_digest="${new_image#*@}"

cat <<EOF >> "${kustomization_arch_file}"
- name: ${container}
newName: ${new_image_name}
digest: ${new_image_digest}
EOF

yq -i -o json ".images += {\"${container}\": \"${new_image}\"}" "${kubeproxy_release_json}"
done # for container
done # for goarch
}

check_for_manifests_changes() {
# Changes to ignore:
# - `release-$ARCH.json` files
Expand Down
70 changes: 70 additions & 0 deletions scripts/auto-rebase/rebase_flannel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

set -o errexit
set -o errtrace
set -o nounset
set -o pipefail

shopt -s expand_aliases
shopt -s extglob

export PS4='+ $(date "+%T.%N") ${BASH_SOURCE#$HOME/}:$LINENO \011'

REPOROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/../..")"
STAGING_DIR="${REPOROOT}/_output/staging"
FLANNEL_VERSION=v0.25.6
FLANNEL_CNI_PLUGIN_VERSION=v1.5.1-flannel2
REGISTRY="docker.io/flannel"
declare -A GOARCH_TO_UNAME_MAP=( ["amd64"]="x86_64" ["arm64"]="aarch64" )
declare -A FLANNEL_MAP=( ["flannel"]="flannel_release.json" ["flannel-plugin"]="flannel-plugin_release.json")

title() {
echo -e "\E[34m$1\E[00m";
}

get_manifest_from_docker() {
title "Downloading manifest for flannel"
mkdir -p "${STAGING_DIR}"
pushd "${STAGING_DIR}" >/dev/null
oc image info ${REGISTRY}/flannel:${FLANNEL_VERSION} --show-multiarch -ojson > "${FLANNEL_MAP["flannel"]}"
oc image info ${REGISTRY}/flannel-cni-plugin:${FLANNEL_CNI_PLUGIN_VERSION} --show-multiarch -ojson > "${FLANNEL_MAP["flannel-plugin"]}"
popd >/dev/null
}


update_flannel_images() {
title "Rebasing flannel images"

for goarch in amd64 arm64; do
arch=${GOARCH_TO_UNAME_MAP["${goarch}"]:-noarch}

local kustomization_arch_file="${REPOROOT}/assets/optional/flannel/kustomization.${arch}.yaml"
local flannel_release_json="${REPOROOT}/assets/optional/flannel/release-flannel-${arch}.json"

jq -n "{\"release\": {\"base\": \"${REGISTRY}\"}, \"images\": {}}" > "${flannel_release_json}"

# Create extra kustomization for each arch in separate file.
# Right file (depending on arch) should be appended during rpmbuild to kustomization.yaml.
cat <<EOF > "${kustomization_arch_file}"

images:
EOF

for container in flannel flannel-plugin; do
new_image_name=$(jq -r ".[] | select(.config.architecture == \"${goarch}\") | .name" "${STAGING_DIR}/${FLANNEL_MAP[${container}]}")
new_image_digest=$(jq -r ".[] | select(.config.architecture == \"${goarch}\") | .digest" "${STAGING_DIR}/${FLANNEL_MAP[${container}]}")
local new_image="${new_image_name%%:*}@${new_image_digest}"

cat <<EOF >> "${kustomization_arch_file}"
- name: ${container}
newName: ${new_image_name%%:*}
digest: ${new_image_digest}
EOF

yq -i -o json ".images += {\"${container}\": \"${new_image}\"}" "${flannel_release_json}"
done # for container
done # for goarch
}

get_manifest_from_docker
update_flannel_images