Skip to content

Commit

Permalink
ibmcloud: fix import.sh bucket selection
Browse files Browse the repository at this point in the history
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 <frankb@ca.ibm.com>
  • Loading branch information
frankbu committed Feb 5, 2025
1 parent e86c09f commit ea804d7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/cloud-api-adaptor/ibmcloud/image/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea804d7

Please sign in to comment.