Skip to content

Commit 40674e7

Browse files
committed
Fix error message when no stable versions are found
Signed-off-by: Dimitris Karakasilis <[email protected]>
1 parent b14f096 commit 40674e7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

.github/public-cloud/cleanup-old-images-aws.sh

+17-14
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,30 @@ snapshotDeleteIfNotInVersionList() {
6969

7070
s3ObjectDeleteIfNotInVersionList() {
7171
local bucket=$1
72-
local key=$2
72+
local objectKey=$2
7373
shift 2
7474
local versionList=("$@")
7575

7676
# Get all S3 object tags and properly parse them
7777
TagExists=false
78-
while IFS=$'\t' read -r key value; do
79-
if [[ "$key" == "KairosVersion" ]]; then
80-
for tagToCheck in "${versionList[@]}"; do
81-
if [[ "$value" == "$tagToCheck" ]]; then
82-
echo "S3 object '$key' in bucket '$bucket' has the '$tagToCheck' tag. Skipping cleanup."
83-
TagExists=true
84-
break 2
85-
fi
86-
done
87-
fi
88-
done < <(AWSNR s3api get-object-tagging --bucket "$bucket" --key "$key" --query 'TagSet[].[Key,Value]' --output text)
78+
# Check if the object has any tags first
79+
if AWSNR s3api get-object-tagging --bucket "$bucket" --key "$objectKey" --query 'length(TagSet)' --output text 2>/dev/null | grep -q '^[0-9]'; then
80+
while IFS=$'\t' read -r tagKey tagValue; do
81+
if [[ "$tagKey" == "KairosVersion" ]]; then
82+
for tagToCheck in "${versionList[@]}"; do
83+
if [[ "$tagValue" == "$tagToCheck" ]]; then
84+
echo "S3 object '$objectKey' in bucket '$bucket' has the '$tagToCheck' tag. Skipping cleanup."
85+
TagExists=true
86+
break 2
87+
fi
88+
done
89+
fi
90+
done < <(AWSNR s3api get-object-tagging --bucket "$bucket" --key "$objectKey" --query 'TagSet[].[Key,Value]' --output text)
91+
fi
8992

9093
if [ "$TagExists" = false ]; then
91-
AWSNR s3api delete-object --bucket "$bucket" --key "$key"
92-
echo "S3 object $key in bucket $bucket deleted because it does not match any of the versions: '${versionList[*]}'."
94+
AWSNR s3api delete-object --bucket "$bucket" --key "$objectKey"
95+
echo "S3 object $objectKey in bucket $bucket deleted because it does not match any of the versions: '${versionList[*]}'."
9396
fi
9497
}
9598

0 commit comments

Comments
 (0)