Skip to content

Commit d1f2140

Browse files
authored
Merge pull request #1828 from atlassian/issue/failing-terminate-cluster-when-no-tags-present
Added error handling for terminating S3
2 parents d38e668 + 24a53ef commit d1f2140

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/util/k8s/terminate_cluster.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,14 @@ def delete_expired_tf_state_s3_buckets():
981981
for bucket in response["Buckets"]:
982982
if bucket_name_template in bucket["Name"]:
983983
created_date = bucket["CreationDate"]
984-
tags = s3_client.get_bucket_tagging(Bucket=bucket["Name"])["TagSet"]
984+
try:
985+
tags = s3_client.get_bucket_tagging(Bucket=bucket["Name"])["TagSet"]
986+
except botocore.exceptions.ClientError as e:
987+
if e.response['Error']['Code'] == 'NoSuchTagSet':
988+
raise RuntimeError(f"S3 bucket {bucket['Name']} does not have any tags.")
989+
else:
990+
logging.error(f"Unexpected error for bucket: {bucket['Name']}")
991+
raise e
985992
persist_days = next((tag["Value"] for tag in tags if tag["Key"] == "persist_days"), None)
986993
if persist_days:
987994
if not is_float(persist_days):
@@ -995,7 +1002,7 @@ def delete_expired_tf_state_s3_buckets():
9951002
logging.info(f"S3 bucket {bucket['Name']} is EOL and should be deleted.")
9961003
delete_bucket_by_name(s3_client, bucket['Name'])
9971004
else:
998-
logging.warning(f"S3 bucket {bucket['Name']} does not have tags.")
1005+
logging.warning(f"S3 bucket {bucket['Name']} is missing persis_days tag.")
9991006

10001007

10011008
def is_policy_attached(policy_arn):

0 commit comments

Comments
 (0)