@@ -8,6 +8,11 @@ log_error() {
8
8
exit " ${2:- 1} " # Exit with provided code or 1 by default
9
9
}
10
10
11
+ # Helper function to log errors
12
+ log_warning () {
13
+ echo " ⚠️ Warning: $1 "
14
+ }
15
+
11
16
# Function to check for required environment variables
12
17
check_env_vars () {
13
18
echo " Checking required environment variables..."
@@ -19,13 +24,42 @@ check_env_vars() {
19
24
[" RELEASE_CATALOG_GIT_REVISION" ]=" Missing RELEASE_CATALOG_GIT_REVISION"
20
25
)
21
26
27
+ # Check core required variables
22
28
for var_name in " ${! required_vars[@]} " ; do
23
29
if [ -z " ${! var_name} " ]; then
24
30
echo " ❌ error: ${required_vars[$var_name]} "
25
31
missing_vars=$(( missing_vars + 1 ))
26
32
fi
27
33
done
28
34
35
+ # Check variables from test.env files (static list of all variables found in test.env files)
36
+ echo " Checking test environment variables..."
37
+ local -a test_env_vars=(
38
+ " application_name"
39
+ " appstudio_component_branch"
40
+ " component_base_branch"
41
+ " component_branch"
42
+ " component_git_url"
43
+ " component_name"
44
+ " component_repo_name"
45
+ " component_type"
46
+ " managed_namespace"
47
+ " managed_sa_name"
48
+ " originating_tool"
49
+ " tenant_namespace"
50
+ " tenant_sa_name"
51
+ )
52
+ for var_name in " ${test_env_vars[@]} " ; do
53
+ # Check if variable is set
54
+ if [ -z " ${! var_name} " ]; then
55
+ echo " ❌ error: Missing test environment variable: $var_name "
56
+ missing_vars=$(( missing_vars + 1 ))
57
+ else
58
+ echo " ✅ $var_name is set"
59
+ fi
60
+ done
61
+
62
+ # Special file validation
29
63
if [ -n " $VAULT_PASSWORD_FILE " ] && [ ! -f " $VAULT_PASSWORD_FILE " ]; then
30
64
echo " ❌ error: env var VAULT_PASSWORD_FILE points to a non-existent file: $VAULT_PASSWORD_FILE "
31
65
missing_vars=$(( missing_vars + 1 ))
@@ -38,7 +72,7 @@ check_env_vars() {
38
72
if [ -n " $KUBECONFIG " ] ; then
39
73
echo " Using provided KUBECONFIG"
40
74
else
41
- echo " ⚠️ Warning: KUBECONFIG is not set. Assuming kubectl is configured correctly."
75
+ log_warning " KUBECONFIG is not set. Assuming kubectl is configured correctly."
42
76
fi
43
77
echo " Environment variable check complete."
44
78
}
@@ -92,7 +126,7 @@ get_build_pipeline_run_url() { # args are ns, app, name
92
126
console_url=${console_url%/ }
93
127
94
128
if [ -z " $console_url " ]; then
95
- echo " ⚠️ Warning: Could not retrieve custom-console-url. URL might be incomplete."
129
+ log_warning " Could not retrieve custom-console-url. URL might be incomplete."
96
130
echo " kubectl get cm/pipelines-as-code -n openshift-pipelines -ojson" # Add command for easier debugging
97
131
echo " ${ns} /applications/${app} /pipelineruns/${name} " # Fallback or partial URL
98
132
else
@@ -150,6 +184,7 @@ cleanup_resources() {
150
184
echo " Killing any child processes..." >> " ${cleanup_log_file} "
151
185
pkill -e -P $$
152
186
187
+ cat " ${cleanup_log_file} "
153
188
if [ " $err " -ne 0 ]; then
154
189
exit " $err "
155
190
fi
@@ -239,21 +274,54 @@ create_kubernetes_resources() {
239
274
# Modifies global variables: component_pr, pr_number
240
275
# Relies on global variables: component_name, tenant_namespace
241
276
wait_for_component_initialization () {
242
- echo -n " Waiting for component ${component_name} in namespace ${tenant_namespace} to be initialized: "
277
+ echo " Waiting for component ${component_name} in namespace ${tenant_namespace} to be initialized..."
278
+
279
+ local max_attempts=60 # 10 minutes with 10-second intervals
280
+ local attempt=1
243
281
local component_annotations=" "
244
- while [ -z " ${component_annotations} " ]; do
245
- sleep 1
246
- echo -n " ."
282
+ local initialization_success=false
283
+
284
+ while [ $attempt -le $max_attempts ]; do
285
+ echo " Initialization check attempt ${attempt} /${max_attempts} ..."
286
+
287
+ # Try to get component annotations
247
288
component_annotations=$( kubectl get component/" ${component_name} " -n " ${tenant_namespace} " -ojson 2> /dev/null | \
248
289
jq -r --arg k " build.appstudio.openshift.io/status" ' .metadata.annotations[$k] // ""' )
290
+
291
+ if [ -n " ${component_annotations} " ]; then
292
+ # component_pr is made global by not declaring it local
293
+ component_pr=$( jq -r ' .pac."merge-url" // ""' <<< " ${component_annotations}" )
294
+ if [ -n " ${component_pr} " ]; then
295
+ echo " ✅ Component initialized successfully"
296
+ initialization_success=true
297
+ break
298
+ else
299
+ log_warning " Could not get component PR from annotations: ${component_annotations} "
300
+ echo " Requesting a new configure-pac..."
301
+ kubectl annotate components/${component_name} build.appstudio.openshift.io/request=configure-pac -n " ${tenant_namespace} "
302
+ echo " Waiting 10 seconds before retry..."
303
+ sleep 10
304
+ fi
305
+
306
+ else
307
+ log_warning " Component not yet initialized (attempt ${attempt} /${max_attempts} )"
308
+
309
+ # Wait before retrying (except on the last attempt)
310
+ if [ $attempt -lt $max_attempts ]; then
311
+ echo " Waiting 10 seconds before retry..."
312
+ sleep 10
313
+ fi
314
+ fi
315
+
316
+ attempt=$(( attempt + 1 ))
249
317
done
250
- echo " "
251
- echo " ️✅️ Initialized."
252
318
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} "
319
+ # Check if initialization ultimately succeeded
320
+ if [ " $initialization_success " = false ]; then
321
+ echo " 🔴 error: component ${component_name} failed to initialize after ${max_attempts} attempts ($(( $max_attempts * 10 / 60 )) minutes)"
322
+ echo " - Component may not exist in namespace ${tenant_namespace} "
323
+ echo " - Component creation may have failed"
324
+ exit 1
257
325
fi
258
326
259
327
# pr_number is made global by not declaring it local
@@ -286,7 +354,7 @@ merge_github_pr() {
286
354
# Retry loop for PR merge
287
355
while [ $attempt -le $max_attempts ] && [ " $success " = false ]; do
288
356
echo " Merge attempt ${attempt} /${max_attempts} ..."
289
-
357
+
290
358
set +e
291
359
merge_result=$( curl -L \
292
360
-X PUT \
@@ -511,7 +579,8 @@ cleanup_old_resources() {
511
579
# - GITHUB_TOKEN environment variable must be set
512
580
delete_old_branches () {
513
581
local repo_name=" $1 "
514
- local cutoff_days=" ${2:- 1} "
582
+ local branch_prefix=" $2 "
583
+ local cutoff_days=" ${3:- 1} "
515
584
516
585
if [ -z " $repo_name " ]; then
517
586
echo " 🔴 Error: Repository name is required (format: owner/repo)"
@@ -531,5 +600,5 @@ delete_old_branches() {
531
600
fi
532
601
533
602
echo " 🔍 Deleting branches in ${repo_name} older than ${cutoff_days} day(s)..."
534
- CUTOFF_DATE=" ${cutoff_days} day" bash " $script_path " " $repo_name "
603
+ CUTOFF_DATE=" ${cutoff_days} day" bash " $script_path " " $repo_name " " $branch_prefix "
535
604
}
0 commit comments