Skip to content

Commit 823c891

Browse files
ci: run e2e cleanup daily (#3819)
* ci: run e2e cleanup job once daily * ci: dont abort cleanup on first error * ci: clean up leftover resources from release workflows --------- Signed-off-by: Daniel Weiße <dw@edgeless.systems>
1 parent f66be95 commit 823c891

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# get_e2e_test_ids_on_date gets all workflow IDs of workflows that contain "e2e" on a specific date.
44
function get_e2e_test_ids_on_date {
5-
ids="$(gh run list --created "$1" --status failure --json createdAt,workflowName,databaseId --jq '.[] | select(.workflowName | contains("e2e") and (contains("MiniConstellation") | not)) | .databaseId' -L1000 -R edgelesssys/constellation || exit 1)"
5+
ids="$(gh run list --created "$1" --status failure --json createdAt,workflowName,databaseId --jq '.[] | select(.workflowName | (contains("e2e") or contains("Release")) and (contains("MiniConstellation") | not)) | .databaseId' -L1000 -R edgelesssys/constellation || exit 1)"
66
echo "${ids}"
77
}
88

@@ -11,24 +11,15 @@ function download_tfstate_artifact {
1111
gh run download "$1" -p "terraform-state-*" -R edgelesssys/constellation > /dev/null
1212
}
1313

14-
# delete_resources runs terraform destroy on the constellation-terraform subfolder of a given folder.
15-
function delete_resources {
16-
if [[ -d "$1/constellation-terraform" ]]; then
17-
cd "$1/constellation-terraform" || exit 1
18-
terraform init > /dev/null || exit 1 # first, install plugins
19-
terraform destroy -auto-approve || exit 1
20-
cd ../../ || exit 1
21-
fi
22-
}
23-
24-
# delete_iam_config runs terraform destroy on the constellation-iam-terraform subfolder of a given folder.
25-
function delete_iam_config {
26-
if [[ -d "$1/constellation-iam-terraform" ]]; then
27-
cd "$1/constellation-iam-terraform" || exit 1
28-
terraform init > /dev/null || exit 1 # first, install plugins
29-
terraform destroy -auto-approve || exit 1
30-
cd ../../ || exit 1
14+
# delete_terraform_resources runs terraform destroy on the given folder.
15+
function delete_terraform_resources {
16+
delete_err=0
17+
if pushd "${1}/${2}"; then
18+
terraform init > /dev/null || delete_err=1 # first, install plugins
19+
terraform destroy -auto-approve || delete_err=1
20+
popd || exit 1
3121
fi
22+
return "${delete_err}"
3223
}
3324

3425
# check if the password for artifact decryption was given
@@ -42,7 +33,7 @@ artifact_pwd=${ENCRYPTION_SECRET}
4233
shopt -s nullglob
4334

4435
start_date=$(date "+%Y-%m-%d")
45-
end_date=$(date --date "-7 day" "+%Y-%m-%d")
36+
end_date=$(date --date "-4 day" "+%Y-%m-%d")
4637
dates_to_clean=()
4738

4839
# get all dates of the last week
@@ -85,13 +76,19 @@ export TF_PLUGIN_CACHE_DIR="${HOME}/tf_plugin_cache"
8576
echo "[*] created terraform cache directory ${TF_PLUGIN_CACHE_DIR}"
8677

8778
echo "[*] deleting resources"
79+
error_occurred=0
8880
for directory in ./terraform-state-*; do
8981
echo " deleting resources in ${directory}"
90-
delete_resources "${directory}"
82+
delete_terraform_resources "${directory}" "constellation-terraform" || echo "[!] deleting resources failed" && error_occurred=1
9183
echo " deleting IAM configuration in ${directory}"
92-
delete_iam_config "${directory}"
84+
delete_terraform_resources "${directory}" "constellation-iam-terraform" || echo "[!] deleting IAM resources failed" && error_occurred=1
9385
echo " deleting directory ${directory}"
9486
rm -rf "${directory}"
9587
done
9688

89+
if [[ ${error_occurred} -ne 0 ]]; then
90+
echo "[!] Errors occurred during resource deletion."
91+
exit 1
92+
fi
93+
9794
exit 0

.github/workflows/e2e-cleanup-weekly.yml renamed to .github/workflows/e2e-cleanup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: e2e weekly cleanup
1+
name: e2e cleanup
22

33
on:
44
schedule:
5-
- cron: "0 0 * * 0" # At 00:00 every Sunday UTC
5+
- cron: "0 0 * * *" # At 00:00 every day
66
workflow_dispatch:
77

88

0 commit comments

Comments
 (0)