Skip to content

Commit e1fdc94

Browse files
committed
add CI to cleanup ci clusters
1 parent 059d0f8 commit e1fdc94

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Cleanup CI clusters
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
ci_cloud:
6+
description: 'Select the CI_CLOUD'
7+
required: true
8+
type: choice
9+
options:
10+
- LEAFCLOUD
11+
- SMS
12+
- ARCUS
13+
schedule:
14+
- cron: '0 4 * * *' # Run at 4AM - image sync runs at midnight
15+
16+
jobs:
17+
ci_cleanup:
18+
name: ci-cleanup
19+
concurrency: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.cloud }}-${{ matrix.build }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
cloud:
24+
- LEAFCLOUD
25+
- SMS
26+
- ARCUS
27+
runs-on: ubuntu-22.04
28+
env:
29+
OS_CLOUD: openstack
30+
CI_CLOUD: ${{ matrix.cloud }}
31+
steps:
32+
- uses: actions/checkout@v2
33+
34+
- name: Record which cloud CI is running on
35+
run: |
36+
echo CI_CLOUD: ${{ env.CI_CLOUD }}
37+
38+
- name: Setup environment
39+
run: |
40+
python3 -m venv venv
41+
. venv/bin/activate
42+
pip install -U pip
43+
pip install $(grep -o 'python-openstackclient[><=0-9\.]*' requirements.txt)
44+
shell: bash
45+
46+
- name: Write clouds.yaml
47+
run: |
48+
mkdir -p ~/.config/openstack/
49+
echo "${{ secrets[format('{0}_CLOUDS_YAML', env.CI_CLOUD)] }}" > ~/.config/openstack/clouds.yaml
50+
shell: bash
51+
52+
- name: Find CI clusters
53+
run: |
54+
. venv/bin/activate
55+
CI_CLUSTERS=$(openstack server list | grep --only-matching 'slurmci-RL.-[0-9]\+' | sort | uniq)
56+
echo "ci_clusters=${CI_CLUSTERS}" >> GITHUB_ENV
57+
shell: bash
58+
59+
- name: Delete clusters if control node not tagged with keep
60+
run: |
61+
. venv/bin/activate
62+
for cluster_prefix in ${CI_CLUSTERS}
63+
do
64+
TAGS=$(openstack server show ${cluster_prefix}-control --column tags --format value)
65+
if [[ TAGS =~ "keep" ]]; then
66+
echo "Skipping ${cluster_prefix} - control instance is tagged as keep"
67+
else
68+
yes | ./dev/delete-cluster.py ${cluster_prefix}
69+
fi
70+
done
71+
shell: bash

0 commit comments

Comments
 (0)