forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (68 loc) · 2.69 KB
/
scale-cleanup-kops.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Cleanup GCE kops clusters
on:
# Run every 3 hours
# In case we leak kops cluster, we want to cleanup
# 100 node cluster pretty fast
schedule:
- cron: '0 */3 * * *'
permissions:
# To be able to access the repository with actions/checkout
contents: read
# To be able to request the JWT from GitHub's OIDC provider
id-token: write
# To allow retrieving information from the PR API
pull-requests: read
concurrency:
# Structure:
# - Workflow name
group: |
${{ github.workflow }}
cancel-in-progress: true
env:
# renovate: datasource=golang-version depName=go
go_version: 1.23.6
# renovate: datasource=docker depName=google/cloud-sdk
gcloud_version: 509.0.0
jobs:
cleanup-kops-clusters:
runs-on: ubuntu-24.04
name: Cleanup kops clusters
timeout-minutes: 30
steps:
- name: Checkout context ref (trusted)
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Set Environment Variables
uses: ./.github/actions/set-env-variables
- name: Install Kops
uses: cilium/scale-tests-action/install-kops@7d8cbd9a2f9d00697f5d2efd5cd064478aa327e0 # main
- name: Setup gcloud credentials
uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
with:
workload_identity_provider: ${{ secrets.GCP_PERF_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_PERF_SA }}
create_credentials_file: true
export_environment_variables: true
- name: Setup gcloud CLI
uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
with:
project_id: ${{ secrets.GCP_PERF_PROJECT_ID }}
version: ${{ env.gcloud_version }}
- name: Cleanup stale clusters
shell: bash
timeout-minutes: 25
run: |
if ./kops get clusters --state ${{ secrets.GCP_PERF_KOPS_STATE_STORE }} -o json > /tmp/clusters.json
then
echo "Clusters list fetched successfully"
date=`date -u +%Y-%m-%d'T'%H:%M'Z' -d "3 hour ago"`
cat /tmp/clusters.json | jq -r --arg date "$date" '.[] | select(.metadata.creationTimestamp < $date) | .metadata.name' > /tmp/stale-clusters.txt
# iterate through list of cluster names in /tmp/stale-clusters.txt
while IFS= read -r cluster; do
./kops delete cluster --state ${{ secrets.GCP_PERF_KOPS_STATE_STORE }} $cluster --yes
done < /tmp/stale-clusters.txt
else
echo "Failed to fetch clusters list, probably no clusters present"
fi