Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions .github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# get_e2e_test_ids_on_date gets all workflow IDs of workflows that contain "e2e" on a specific date.
function get_e2e_test_ids_on_date {
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)"
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)"
echo "${ids}"
}

Expand All @@ -14,20 +14,20 @@ function download_tfstate_artifact {
# delete_resources runs terraform destroy on the constellation-terraform subfolder of a given folder.
function delete_resources {
if [[ -d "$1/constellation-terraform" ]]; then
cd "$1/constellation-terraform" || exit 1
terraform init > /dev/null || exit 1 # first, install plugins
terraform destroy -auto-approve || exit 1
cd ../../ || exit 1
cd "$1/constellation-terraform" || return 1
terraform init > /dev/null || return 1 # first, install plugins
terraform destroy -auto-approve || return 1
cd ../../ || return 1
fi
}

# delete_iam_config runs terraform destroy on the constellation-iam-terraform subfolder of a given folder.
function delete_iam_config {
if [[ -d "$1/constellation-iam-terraform" ]]; then
cd "$1/constellation-iam-terraform" || exit 1
terraform init > /dev/null || exit 1 # first, install plugins
terraform destroy -auto-approve || exit 1
cd ../../ || exit 1
cd "$1/constellation-iam-terraform" || return 1
terraform init > /dev/null || return 1 # first, install plugins
terraform destroy -auto-approve || return 1
cd ../../ || return 1
fi
}

Expand All @@ -42,7 +42,7 @@ artifact_pwd=${ENCRYPTION_SECRET}
shopt -s nullglob

start_date=$(date "+%Y-%m-%d")
end_date=$(date --date "-7 day" "+%Y-%m-%d")
end_date=$(date --date "-14 day" "+%Y-%m-%d")
dates_to_clean=()

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

echo "[*] deleting resources"
error_occurred=0
for directory in ./terraform-state-*; do
echo " deleting resources in ${directory}"
delete_resources "${directory}"
delete_resources "${directory}" || error_occurred=1
echo " deleting IAM configuration in ${directory}"
delete_iam_config "${directory}"
delete_iam_config "${directory}" || error_occurred=1
echo " deleting directory ${directory}"
rm -rf "${directory}"
done

if [[ ${error_occurred} -ne 0 ]]; then
echo "[!] Errors occurred during resource deletion."
exit 1
fi

exit 0
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: e2e weekly cleanup
name: e2e cleanup

on:
schedule:
- cron: "0 0 * * 0" # At 00:00 every Sunday UTC
- cron: "0 0 * * *" # At 00:00 every day
workflow_dispatch:


Expand Down