@@ -239,21 +239,55 @@ create_kubernetes_resources() {
239
239
# Modifies global variables: component_pr, pr_number
240
240
# Relies on global variables: component_name, tenant_namespace
241
241
wait_for_component_initialization () {
242
- echo -n " Waiting for component ${component_name} in namespace ${tenant_namespace} to be initialized: "
242
+ echo " Waiting for component ${component_name} in namespace ${tenant_namespace} to be initialized..."
243
+
244
+ local max_attempts=60 # 10 minutes with 10-second intervals
245
+ local attempt=1
243
246
local component_annotations=" "
244
- while [ -z " ${component_annotations} " ]; do
245
- sleep 1
246
- echo -n " ."
247
+ local initialization_success=false
248
+
249
+ while [ $attempt -le $max_attempts ]; do
250
+ echo " Initialization check attempt ${attempt} /${max_attempts} ..."
251
+
252
+ # Try to get component annotations
247
253
component_annotations=$( kubectl get component/" ${component_name} " -n " ${tenant_namespace} " -ojson 2> /dev/null | \
248
254
jq -r --arg k " build.appstudio.openshift.io/status" ' .metadata.annotations[$k] // ""' )
255
+
256
+ if [ -n " ${component_annotations} " ]; then
257
+ echo " ✅ Component initialized successfully"
258
+
259
+ # component_pr is made global by not declaring it local
260
+ component_pr=$( jq -r ' .pac."merge-url" // ""' <<< " ${component_annotations}" )
261
+ if [ -n " ${component_pr} " ]; then
262
+ initialization_success=true
263
+ break
264
+ else
265
+ log_warning " Could not get component PR from annotations: ${component_annotations} "
266
+ echo " Waiting 10 seconds before retry..."
267
+ sleep 10
268
+ echo " Requesting a new configure-pac..."
269
+ kubectl annotate components/${component_name} build.appstudio.openshift.io/request=configure-pac -n " ${tenant_namespace} "
270
+ fi
271
+
272
+ else
273
+ echo " ⚠️ Component not yet initialized (attempt ${attempt} /${max_attempts} )"
274
+
275
+ # Wait before retrying (except on the last attempt)
276
+ if [ $attempt -lt $max_attempts ]; then
277
+ echo " Waiting 10 seconds before retry..."
278
+ sleep 10
279
+ fi
280
+ fi
281
+
282
+ attempt=$(( attempt + 1 ))
249
283
done
250
- echo " "
251
- echo " ️✅️ Initialized."
252
284
253
- # component_pr is made global by not declaring it local
254
- component_pr=$( jq -r ' .pac."merge-url" // ""' <<< " ${component_annotations}" )
255
- if [ -z " ${component_pr} " ]; then
256
- log_error " Could not get component PR from annotations: ${component_annotations} "
285
+ # Check if initialization ultimately succeeded
286
+ if [ " $initialization_success " = false ]; then
287
+ echo " 🔴 error: component ${component_name} failed to initialize after ${max_attempts} attempts ($(( $max_attempts * 10 / 60 )) minutes)"
288
+ echo " - Component may not exist in namespace ${tenant_namespace} "
289
+ echo " - Component creation may have failed"
290
+ exit 1
257
291
fi
258
292
259
293
# pr_number is made global by not declaring it local
@@ -286,7 +320,7 @@ merge_github_pr() {
286
320
# Retry loop for PR merge
287
321
while [ $attempt -le $max_attempts ] && [ " $success " = false ]; do
288
322
echo " Merge attempt ${attempt} /${max_attempts} ..."
289
-
323
+
290
324
set +e
291
325
merge_result=$( curl -L \
292
326
-X PUT \
0 commit comments