From 8cb7d78f58845a98aac808ec74c41837dc038e8a Mon Sep 17 00:00:00 2001 From: Frank Budinsky Date: Wed, 5 Feb 2025 17:26:23 -0500 Subject: [PATCH] ibmcloud: fix import.sh bucket selection Choosing the first bucket in an instance wil not work if the first bucket is not in the target region. This PR fixes the selection logic to choose the first bucket that is in the target region. Signed-off-by: Frank Budinsky --- src/cloud-api-adaptor/ibmcloud/image/import.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cloud-api-adaptor/ibmcloud/image/import.sh b/src/cloud-api-adaptor/ibmcloud/image/import.sh index ca86235c3..acc13412b 100755 --- a/src/cloud-api-adaptor/ibmcloud/image/import.sh +++ b/src/cloud-api-adaptor/ibmcloud/image/import.sh @@ -66,16 +66,20 @@ fi [ -n "$endpoint" ] && ibmcloud cos config endpoint-url --url "$endpoint" >/dev/null -if ! ibmcloud cos buckets --output JSON | jq -r '.Buckets[].Name'; then - error "Can't find any buckets in $instance" -fi - if [ -z "$bucket" ]; then - bucket=$(ibmcloud cos buckets --output JSON | jq -r '.Buckets[0].Name') + for i in $(ibmcloud cos buckets --output JSON | jq -r '.Buckets[].Name'); do + if ibmcloud cos bucket-head --bucket $i >/dev/null 2>&1; then + bucket=$i + break + fi + done + if [ -z "$bucket" ]; then + error "Can't find any buckets in target region" + fi +else + ibmcloud cos bucket-head --bucket "$bucket" || error "Bucket $bucket not found" fi -ibmcloud cos bucket-head --bucket "$bucket" || error "Bucket $bucket not found" - if [ -f ${image_file} ]; then file=${image_file} else