Skip to content

Commit 65dec94

Browse files
mads-hartmannroboquat
authored andcommitted
Run cleanup job on each Werft build node
1 parent eff6f0a commit 65dec94

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

.werft/platform-clean-up-werft-build-nodes.yaml renamed to .werft/platform-clean-up-werft-build-node.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
#
2+
# This job is responsible for cleaning up a single Werft build node.
3+
#
4+
# The nodeAffinity ensures this is executed on a specific node and we rely on
5+
# volume mounts for getting access to the disk
6+
#
7+
# This job is being triggered for each build node periodically by .werft/platform-trigger-werft-cleanup.yaml
8+
# but you can also run it manually for a specific node like so:
9+
#
10+
# werft job run github -j .werft/platform-clean-up-werft-build-node.yaml -a node=gke-core-dev-builds-0-294352e4-mxkv
11+
#
112
pod:
213
serviceAccount: werft
314
affinity:
415
nodeAffinity:
516
requiredDuringSchedulingIgnoredDuringExecution:
617
nodeSelectorTerms:
718
- matchExpressions:
8-
- key: dev/workload
19+
- key: "kubernetes.io/hostname"
920
operator: In
1021
values:
11-
- "builds"
22+
- "{{ .Annotations.node }}"
1223
volumes:
1324
- name: werft-build-caches
1425
hostPath:
@@ -43,5 +54,3 @@ pod:
4354
4455
werft log phase werft-build-cache-prune "Cleaning up Werft build caches older than 12 hours"
4556
find /werft-build-caches/* -maxdepth 0 -mmin +720 -print -exec sudo rm -rf "{}" \; | werft log slice werft-build-cache-prune
46-
plugins:
47-
cron: "@midnight"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# This job is responsible for triggering the .werft/platform-clean-up-werft-build-node.yaml job
3+
# for each node that has the dev/workload label set to "builds"
4+
#
5+
# It is a Werft cron job that runs periodically but you can always manually trigger it using
6+
#
7+
# werft job run github -j .werft/platform-trigger-werft-cleanup.yaml
8+
#
9+
pod:
10+
serviceAccount: werft
11+
affinity:
12+
nodeAffinity:
13+
requiredDuringSchedulingIgnoredDuringExecution:
14+
nodeSelectorTerms:
15+
- matchExpressions:
16+
- key: dev/workload
17+
operator: In
18+
values:
19+
- "builds"
20+
volumes:
21+
# Needed to install the core-dev kubectl context to talk to Werft
22+
- name: gcp-sa
23+
secret:
24+
secretName: gcp-sa-gitpod-dev-deployer
25+
containers:
26+
- name: build
27+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:cw-werft-cred.0
28+
workingDir: /workspace
29+
imagePullPolicy: IfNotPresent
30+
env:
31+
- name: WERFT_K8S_NAMESPACE
32+
value: werft
33+
- name: WERFT_DIAL_MODE
34+
value: kubernetes
35+
- name: WERFT_CREDENTIAL_HELPER
36+
value: ""
37+
volumeMounts:
38+
- name: gcp-sa
39+
mountPath: /mnt/secrets/gcp-sa
40+
readOnly: true
41+
command:
42+
- bash
43+
- -c
44+
- |
45+
sleep 1
46+
set -Eeuo pipefail
47+
48+
# This is needed to run Werft jobs from Github
49+
sudo chown -R gitpod:gitpod /workspace
50+
git config --global user.name roboquat
51+
git config --global user.email roboquat@gitpod.io
52+
53+
# Install core-dev context
54+
gcloud auth activate-service-account --key-file "/mnt/secrets/gcp-sa/service-account.json"
55+
gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev
56+
57+
echo "[Triggering clean up jobs|PHASE] Triggering the cleanup job for each node"
58+
59+
nodes=$(kubectl get nodes -l dev/workload=builds --no-headers -o custom-columns=":metadata.name")
60+
61+
for node in $nodes ; do
62+
echo "[Cleanup up node $node] Triggering the cleanup job for $node"
63+
werft job run github -j .werft/platform-clean-up-werft-build-node.yaml -a node="$node" \
64+
| werft log slice "Cleanup up node $node"
65+
echo "[Cleanup up node $node|DONE]"
66+
done
67+
plugins:
68+
cron: "@midnight"

0 commit comments

Comments
 (0)