Skip to content

Commit 17742ec

Browse files
authored
temporary workaround for OCPBUGS-78431 (#76504)
1 parent 02d545d commit 17742ec

1 file changed

Lines changed: 112 additions & 38 deletions

File tree

ci-operator/step-registry/ipi/conf/gcp/zones/ipi-conf-gcp-zones-commands.sh

Lines changed: 112 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ echo "$(date -u --rfc-3339=seconds) - INFO: CONTROL_PLANE_ZONES '${CONTROL_PLANE
1717
echo "$(date -u --rfc-3339=seconds) - INFO: CONTROL_PLANE_NODE_TYPE '${CONTROL_PLANE_NODE_TYPE}'"
1818

1919
function get_zones_from_region() {
20+
# shellcheck disable=SC2178
21+
local -n ZONES=$1
22+
2023
if [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
2124
echo "$(date -u --rfc-3339=seconds) - INFO: Filtering zones by the exclusion pattern '${ZONES_EXCLUSION_PATTERN}'"
2225
mapfile -t AVAILABILITY_ZONES < <(gcloud compute zones list --filter="region:${GCP_REGION} AND status:UP" --format='value(name)' | grep -v "${ZONES_EXCLUSION_PATTERN}" | shuf)
@@ -26,14 +29,15 @@ function get_zones_from_region() {
2629

2730
echo "$(date -u --rfc-3339=seconds) - INFO: Take the first ${ZONES_COUNT} zones"
2831
ZONES=("${AVAILABILITY_ZONES[@]:0:${ZONES_COUNT}}")
29-
ZONES_STR="[ $(join_by , "${ZONES[@]}") ]"
30-
echo "$(date -u --rfc-3339=seconds) - INFO: GCP region: ${GCP_REGION} (zones: ${ZONES_STR})"
32+
echo "$(date -u --rfc-3339=seconds) - INFO: GCP region: ${GCP_REGION} (zones: ${ZONES[*]})"
3133
}
3234

3335
function join_by { local IFS="$1"; shift; echo "$*"; }
3436

3537
function get_zones_by_machine_type() {
3638
local machine_type=$1
39+
# shellcheck disable=SC2178
40+
local -n ZONES=$2
3741

3842
if [[ -z "${machine_type}" ]]; then
3943
echo "$(date -u --rfc-3339=seconds) - INFO: Nothing to do for empty machine type"
@@ -76,8 +80,37 @@ function get_zones_by_machine_type() {
7680

7781
echo "$(date -u --rfc-3339=seconds) - INFO: Take the first ${ZONES_COUNT} zones"
7882
ZONES=("${AVAILABILITY_ZONES[@]:0:${ZONES_COUNT}}")
79-
ZONES_STR="[ $(join_by , "${ZONES[@]}") ]"
80-
echo "$(date -u --rfc-3339=seconds) - INFO: [${machine_type}] GCP region: ${GCP_REGION} (zones: ${ZONES_STR})"
83+
echo "$(date -u --rfc-3339=seconds) - INFO: [${machine_type}] GCP region: ${GCP_REGION} (zones: ${ZONES[*]})"
84+
}
85+
86+
# Function to get intersection or fallback
87+
# Updates the first array (target) with intersection or fallback logic
88+
function array_intersection_or_fallback() {
89+
local -n target_array=$1
90+
local -n source_array=$2
91+
92+
# If target_array is empty, use source_array
93+
if [ ${#target_array[@]} -eq 0 ]; then
94+
target_array=("${source_array[@]}")
95+
return
96+
fi
97+
98+
# If source_array is empty, keep target_array as is
99+
if [ ${#source_array[@]} -eq 0 ]; then
100+
return
101+
fi
102+
103+
# Both arrays have elements, find intersection
104+
local result=()
105+
for elem1 in "${target_array[@]}"; do
106+
for elem2 in "${source_array[@]}"; do
107+
if [ "$elem1" = "$elem2" ]; then
108+
result+=("$elem1")
109+
break
110+
fi
111+
done
112+
done
113+
target_array=("${result[@]}")
81114
}
82115

83116
export GCP_SHARED_CREDENTIALS_FILE="${CLUSTER_PROFILE_DIR}/gce.json"
@@ -89,64 +122,105 @@ then
89122
gcloud config set project "${GOOGLE_PROJECT_ID}"
90123
fi
91124

92-
ZONES_STR=""
93-
MACHINE_TYPE=""
94-
if [[ -n "${COMPUTE_ZONES}" ]]; then
95-
ZONES_STR="${COMPUTE_ZONES}"
96-
elif [[ -n "${COMPUTE_NODE_TYPE}" ]]; then
97-
MACHINE_TYPE="${COMPUTE_NODE_TYPE}"
98-
elif [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
125+
# As a temporary workaround of https://redhat.atlassian.net/browse/OCPBUGS-78431,
126+
# ensure the compute & controlPlane machines will be deployed into the same set of zones.
127+
# the intersection of ZONES_ARRAY1 and ZONES_ARRAY2
128+
CANDIDATE_ZONES_ARRAY=()
129+
130+
# compute/worker zones string, e.g. '[us-central1-a us-central1-b]'
131+
ZONES_STR1=""
132+
# compute/worker zones array, e.g. (us-central1-a us-central1-b)
133+
ZONES_ARRAY1=()
134+
135+
# control-plane zones string, e.g. '[us-central1-b us-central1-c]'
136+
ZONES_STR2=""
137+
# control-plane zones array, e.g. (us-central1-b us-central1-c)
138+
ZONES_ARRAY2=()
139+
140+
# Get compute/worker machine type
141+
MACHINE_TYPE1=""
142+
if [[ -n "${COMPUTE_NODE_TYPE}" ]]; then
143+
MACHINE_TYPE1="${COMPUTE_NODE_TYPE}"
144+
else
99145
echo "$(date -u --rfc-3339=seconds) - INFO: Extracting compute node type from install-config"
100-
MACHINE_TYPE=$(yq-go r "${CONFIG}" compute[0].platform.gcp.type)
101-
if [[ -z "${MACHINE_TYPE}" ]]; then
102-
MACHINE_TYPE=$(yq-go r "${CONFIG}" platform.gcp.defaultMachinePlatform.type)
146+
MACHINE_TYPE1=$(yq-go r "${CONFIG}" compute[0].platform.gcp.type)
147+
if [[ -z "${MACHINE_TYPE1}" ]]; then
148+
MACHINE_TYPE1=$(yq-go r "${CONFIG}" platform.gcp.defaultMachinePlatform.type)
149+
fi
150+
fi
151+
echo "$(date -u --rfc-3339=seconds) - INFO: compute/worker machine type is '${MACHINE_TYPE1}'"
152+
153+
# Get control-plane machine type
154+
MACHINE_TYPE2=""
155+
if [[ -n "${CONTROL_PLANE_NODE_TYPE}" ]]; then
156+
MACHINE_TYPE2="${CONTROL_PLANE_NODE_TYPE}"
157+
else
158+
echo "$(date -u --rfc-3339=seconds) - INFO: Extracting control-plane node type from install-config"
159+
MACHINE_TYPE2=$(yq-go r "${CONFIG}" controlPlane.platform.gcp.type)
160+
if [[ -z "${MACHINE_TYPE2}" ]]; then
161+
MACHINE_TYPE2=$(yq-go r "${CONFIG}" platform.gcp.defaultMachinePlatform.type)
162+
fi
163+
fi
164+
echo "$(date -u --rfc-3339=seconds) - INFO: control-plane machine type is '${MACHINE_TYPE2}'"
165+
166+
if [[ -z "${COMPUTE_ZONES}" ]]; then
167+
echo "$(date -u --rfc-3339=seconds) - INFO: COMPUTE_ZONES unspecified, getting the candidate zones by compute/worker machine type '${MACHINE_TYPE1}'"
168+
get_zones_by_machine_type "${MACHINE_TYPE1}" ZONES_ARRAY1
169+
170+
if [[ ${#ZONES_ARRAY1[@]} -eq 0 ]] && [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
171+
echo "$(date -u --rfc-3339=seconds) - INFO: Found no zone for machine type '${MACHINE_TYPE1}', possibly a custom machine type. Filtering among all zones instead..."
172+
get_zones_from_region ZONES_ARRAY1
173+
fi
174+
echo "$(date -u --rfc-3339=seconds) - INFO: As a temporary workaround of https://redhat.atlassian.net/browse/OCPBUGS-78431, ensure the zones of compute & controlPlane machines are the same"
175+
array_intersection_or_fallback CANDIDATE_ZONES_ARRAY ZONES_ARRAY1
176+
fi
177+
178+
if [[ -z "${CONTROL_PLANE_ZONES}" ]]; then
179+
echo "$(date -u --rfc-3339=seconds) - INFO: CONTROL_PLANE_ZONES unspecified, getting the candidate zones by control-plane machine type '${MACHINE_TYPE2}'"
180+
get_zones_by_machine_type "${MACHINE_TYPE2}" ZONES_ARRAY2
181+
182+
if [[ ${#ZONES_ARRAY2[@]} -eq 0 ]] && [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
183+
echo "$(date -u --rfc-3339=seconds) - INFO: Found no zone for machine type '${MACHINE_TYPE2}', possibly a custom machine type. Filtering among all zones instead..."
184+
get_zones_from_region ZONES_ARRAY2
103185
fi
186+
echo "$(date -u --rfc-3339=seconds) - INFO: As a temporary workaround of https://redhat.atlassian.net/browse/OCPBUGS-78431, ensure the zones of compute & controlPlane machines are the same"
187+
array_intersection_or_fallback CANDIDATE_ZONES_ARRAY ZONES_ARRAY2
104188
fi
105-
get_zones_by_machine_type "${MACHINE_TYPE}"
106-
if [[ -z "${ZONES_STR}" ]] && [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
107-
echo "$(date -u --rfc-3339=seconds) - INFO: Found no zone for machine type '${MACHINE_TYPE}', possibly a custom machine type. Filtering among all zones instead..."
108-
get_zones_from_region
189+
190+
if [[ -n "${COMPUTE_ZONES}" ]]; then
191+
echo "$(date -u --rfc-3339=seconds) - INFO: COMPUTE_ZONES specified, '${COMPUTE_ZONES}', using it for compute/worker machines"
192+
ZONES_STR1="${COMPUTE_ZONES}"
193+
elif [[ ${#CANDIDATE_ZONES_ARRAY[@]} -gt 0 ]]; then
194+
ZONES_STR1="[ $(join_by , "${CANDIDATE_ZONES_ARRAY[@]}") ]"
109195
fi
110196

111-
if [[ -n "${ZONES_STR}" ]]; then
197+
if [[ -n "${ZONES_STR1}" ]]; then
112198
cat >> "${PATCH}" << EOF
113199
compute:
114200
- name: worker
115201
platform:
116202
gcp:
117-
zones: ${ZONES_STR}
203+
zones: ${ZONES_STR1}
118204
EOF
119205
yq-go m -x -i "${CONFIG}" "${PATCH}"
120206
else
121207
echo "$(date -u --rfc-3339=seconds) - INFO: Skipped setting zones for compute"
122208
fi
123209

124-
ZONES_STR=""
125-
MACHINE_TYPE=""
126210
if [[ -n "${CONTROL_PLANE_ZONES}" ]]; then
127-
ZONES_STR="${CONTROL_PLANE_ZONES}"
128-
elif [[ -n "${CONTROL_PLANE_NODE_TYPE}" ]]; then
129-
MACHINE_TYPE="${CONTROL_PLANE_NODE_TYPE}"
130-
elif [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
131-
echo "$(date -u --rfc-3339=seconds) - INFO: Extracting control-plane node type from install-config"
132-
MACHINE_TYPE=$(yq-go r "${CONFIG}" controlPlane.platform.gcp.type)
133-
if [[ -z "${MACHINE_TYPE}" ]]; then
134-
MACHINE_TYPE=$(yq-go r "${CONFIG}" platform.gcp.defaultMachinePlatform.type)
135-
fi
136-
fi
137-
get_zones_by_machine_type "${MACHINE_TYPE}"
138-
if [[ -z "${ZONES_STR}" ]] && [[ -n "${ZONES_EXCLUSION_PATTERN}" ]]; then
139-
echo "$(date -u --rfc-3339=seconds) - INFO: Found no zone for machine type '${MACHINE_TYPE}', possibly a custom machine type. Filtering among all zones instead..."
140-
get_zones_from_region
211+
echo "$(date -u --rfc-3339=seconds) - INFO: CONTROL_PLANE_ZONES specified, '${CONTROL_PLANE_ZONES}', using it for control-plane machines"
212+
ZONES_STR2="${CONTROL_PLANE_ZONES}"
213+
elif [[ ${#CANDIDATE_ZONES_ARRAY[@]} -gt 0 ]]; then
214+
ZONES_STR2="[ $(join_by , "${CANDIDATE_ZONES_ARRAY[@]}") ]"
141215
fi
142216

143-
if [[ -n "${ZONES_STR}" ]]; then
217+
if [[ -n "${ZONES_STR2}" ]]; then
144218
cat >> "${PATCH}" << EOF
145219
controlPlane:
146220
name: master
147221
platform:
148222
gcp:
149-
zones: ${ZONES_STR}
223+
zones: ${ZONES_STR2}
150224
EOF
151225
yq-go m -x -i "${CONFIG}" "${PATCH}"
152226
else

0 commit comments

Comments
 (0)