Skip to content

Commit 3a5d82d

Browse files
committed
CI: Add a workflow to clean up stale instances
1 parent e00fea3 commit 3a5d82d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: Clean up stale CI resources
3+
on:
4+
push:
5+
branches:
6+
- yoga-aio-tags
7+
schedule:
8+
# Every 2 hours at quarter past
9+
- cron: '15 0/2 * * *'
10+
11+
jobs:
12+
ci-cleanup:
13+
name: Clean up stale CI resources
14+
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
15+
runs-on: ubuntu-latest
16+
permissions: {}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
path: src/kayobe-config
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
26+
- name: Generate clouds.yaml
27+
run: |
28+
cat << EOF > clouds.yaml
29+
${{ secrets.CLOUDS_YAML }}
30+
EOF
31+
32+
- name: Determine OpenStack release
33+
id: openstack_release
34+
run: |
35+
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' src/kayobe-config/.gitreview)
36+
echo "openstack_release=${BRANCH}" | sed "s|stable/||" >> $GITHUB_OUTPUT
37+
38+
- name: Install OpenStack client
39+
run: |
40+
pip install python-openstackclient -c https://opendev.org/openstack/requirements/raw/branch/stable/${{ steps.openstack_release.outputs.openstack_release }}/upper-constraints.txt
41+
42+
- name: Clean up aio instances over 3 hours old
43+
run: |
44+
result=0
45+
changes_before=$(date -Imin -d -4hours)
46+
for status in ACTIVE ERROR SHUTOFF; do
47+
for instance in $(openstack server list --tags skc-ci-aio --os-compute-api-version 2.66 --format value --column Name --changes-before $changes_before --status $status); do
48+
echo "Cleaning up $status instance $instance"
49+
openstack server show $instance
50+
#if ! openstack server delete $instance; then
51+
# echo "Failed to delete $status instance $instance"
52+
# result=1
53+
#fi
54+
done
55+
done
56+
exit $result
57+
env:
58+
OS_CLOUD: openstack
59+
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
60+
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}

0 commit comments

Comments
 (0)