Skip to content

Commit bbad4d6

Browse files
Merge pull request #6519 from pacevedom/configure-vm-5.0
NO-ISSUE: Fix get_latest_rhocp_repo to support crossing major versions
2 parents 6796171 + 48fab8c commit bbad4d6

2 files changed

Lines changed: 47 additions & 23 deletions

File tree

scripts/devenv-builder/configure-vm.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,19 @@ function configure_rhel_repositories() {
218218
sudo subscription-manager repos --enable "rhocp-${ocp_major}.${RHOCP}-for-rhel-9-$(uname -m)-rpms"
219219
elif [[ "${RHOCP}" =~ ^http ]]; then
220220
url=$(echo "${RHOCP}" | cut -d, -f1)
221-
ver=$(echo "${RHOCP}" | cut -d, -f2)
222-
OCP_REPO_NAME="rhocp-${ocp_major}.${ver}-for-rhel-9-mirrorbeta-$(uname -i)-rpms"
221+
major=$(echo "${RHOCP}" | cut -d, -f2)
222+
ver=$(echo "${RHOCP}" | cut -d, -f3)
223+
OCP_REPO_NAME="rhocp-${major}.${ver}-for-rhel-9-mirrorbeta-$(uname -i)-rpms"
223224
sudo tee "/etc/yum.repos.d/${OCP_REPO_NAME}.repo" >/dev/null <<EOF
224225
[${OCP_REPO_NAME}]
225-
name=Beta rhocp-${ocp_major}.${ver} RPMs for RHEL 9
226+
name=Beta rhocp-${major}.${ver} RPMs for RHEL 9
226227
baseurl=${url}
227228
enabled=1
228229
gpgcheck=0
229230
skip_if_unavailable=0
230231
EOF
231232
# Calculate Y-1 version
232-
get_prev_version "${ocp_major}" "${ver}"
233+
get_prev_version "${major}" "${ver}"
233234
if [[ -n "${prev_minor}" ]]; then
234235
PREVIOUS_RHOCP=$("${RHOCP_REPO}" "${prev_minor}" "${prev_major}")
235236
if [[ "${PREVIOUS_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then

scripts/get-latest-rhocp-repo.sh

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,32 @@
1414
#
1515
# Output is:
1616
# - just a minor version in case of subscription RHOCP repository, e.g.: 15
17-
# - or an URL to beta mirror followed by comma and minor version, e.g.:
18-
# https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rpms/4.16-el9-beta/,16
19-
# https://mirror.openshift.com/pub/openshift-v5/x86_64/dependencies/rpms/5.0-el9-beta/,0
17+
# - or an URL to beta mirror followed by comma, major, comma, and minor version, e.g.:
18+
# https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rpms/4.16-el9-beta/,4,16
19+
# https://mirror.openshift.com/pub/openshift-v5/x86_64/dependencies/rpms/5.0-el9-beta/,5,0
2020

2121
set -euo pipefail
2222

2323
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2424
REPOROOT="$(cd "${SCRIPTDIR}/.." && pwd)"
2525

26+
# Map of last minor version for each major (for cross-major transitions)
27+
declare -A LAST_MINOR_FOR_MAJOR=([4]=22)
28+
29+
# Calculate previous version handling cross-major boundaries.
30+
# Sets prev_major and prev_minor variables in the caller's scope.
31+
get_prev_version() {
32+
local major=$1
33+
local minor=$2
34+
if (( minor > 0 )); then
35+
prev_major="${major}"
36+
prev_minor=$(( minor - 1 ))
37+
else
38+
prev_major=$(( major - 1 ))
39+
prev_minor="${LAST_MINOR_FOR_MAJOR[${prev_major}]:-}"
40+
fi
41+
}
42+
2643
if ! sudo subscription-manager status >&/dev/null; then
2744
>&2 echo "System must be subscribed"
2845
exit 1
@@ -44,39 +61,45 @@ if [[ "$#" -ge 2 ]]; then
4461
# Both minor and major provided as arguments
4562
current_minor="${1}"
4663
current_major="${2}"
47-
stop="${current_minor}"
64+
max_steps=1
4865
elif [[ "$#" -eq 1 ]]; then
4966
# Only minor provided, get major from Makefile
5067
current_minor="${1}"
5168
current_major=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)
52-
stop="${current_minor}"
69+
max_steps=1
5370
else
5471
# No arguments, get both from Makefile
5572
current_major=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)
5673
current_minor=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f2)
57-
stop=$(( current_minor - 3 ))
58-
if (( stop < 0 )); then
59-
stop=0
60-
fi
74+
max_steps=4
6175
fi
6276

63-
# Go through minor versions, starting from current_minor counting down
64-
# to get latest available rhocp repository.
65-
# For example, if current version is 4.16, the code will try to access
66-
# rhocp-4.15 (which may not be released yet) and then rhocp-4.14 (which
67-
# will be returned if it's usable). Works similarly for version 5.x.
68-
for ver in $(seq "${current_minor}" -1 "${stop}"); do
69-
repository="rhocp-${current_major}.${ver}-for-rhel-9-$(uname -m)-rpms"
77+
# Go through versions, starting from current version counting down
78+
# to get latest available rhocp repository. Handles cross-major
79+
# boundaries (e.g. from 5.0 back to 4.22).
80+
check_major="${current_major}"
81+
check_minor="${current_minor}"
82+
for (( step=0; step < max_steps; step++ )); do
83+
repository="rhocp-${check_major}.${check_minor}-for-rhel-9-$(uname -m)-rpms"
7084
if sudo dnf repository-packages --showduplicates "${repository}" info cri-o 1>&2; then
71-
echo "${ver}"
85+
echo "${check_minor}"
7286
exit 0
7387
fi
7488

75-
rhocp_beta_url="https://mirror.openshift.com/pub/openshift-v${current_major}/$(uname -m)/dependencies/rpms/${current_major}.${ver}-el9-beta/"
89+
rhocp_beta_url="https://mirror.openshift.com/pub/openshift-v${check_major}/$(uname -m)/dependencies/rpms/${check_major}.${check_minor}-el9-beta/"
7690
if sudo dnf repository-packages --showduplicates --disablerepo '*' --repofrompath "this,${rhocp_beta_url}" this info cri-o 1>&2; then
77-
echo "${rhocp_beta_url},${ver}"
91+
echo "${rhocp_beta_url},${check_major},${check_minor}"
7892
exit 0
7993
fi
94+
95+
prev_major=""
96+
prev_minor=""
97+
get_prev_version "${check_major}" "${check_minor}"
98+
if [[ -z "${prev_minor}" ]]; then
99+
break
100+
fi
101+
check_major="${prev_major}"
102+
check_minor="${prev_minor}"
80103
done
81104

82105
>&2 echo "Failed to get latest rhocp repository!"

0 commit comments

Comments
 (0)