Skip to content

Commit 9a2386f

Browse files
committed
✨ Add Helm hook to roll out osu-web pods by age
1 parent 8489395 commit 9a2386f

3 files changed

Lines changed: 121 additions & 2 deletions

File tree

osu/osu-web/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 2025.1013.0
18+
version: 2025.1025.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "2025.1013.0"
24+
appVersion: "2025.1025.0"
2525

2626
dependencies:
2727
- name: osu-beatmap-difficulty-lookup-cache
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# This hook sets the `controller.kubernetes.io/pod-deletion-cost` on every pod to the creation timestamp.
2+
# The Kubernetes rollout will then terminate pods by order of creation, allowing topologySpreadConstraints to succeed in environments with not much nodes headroom.
3+
{{- if .Values.upgradeOrderJob.enabled }}
4+
---
5+
apiVersion: v1
6+
kind: ServiceAccount
7+
metadata:
8+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
9+
labels:
10+
{{- include "osu-web-chart.labels" (dict "root" . "options" (dict "component" "upgrade-order")) | nindent 4 }}
11+
tier: wait-for-deploy
12+
annotations:
13+
"helm.sh/hook": pre-upgrade
14+
"helm.sh/hook-weight": "-5"
15+
"helm.sh/hook-delete-policy": before-hook-creation
16+
---
17+
apiVersion: rbac.authorization.k8s.io/v1
18+
kind: Role
19+
metadata:
20+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
21+
labels:
22+
{{- include "osu-web-chart.labels" (dict "root" . "options" (dict "component" "upgrade-order")) | nindent 4 }}
23+
tier: wait-for-deploy
24+
annotations:
25+
"helm.sh/hook": pre-upgrade
26+
"helm.sh/hook-weight": "-5"
27+
"helm.sh/hook-delete-policy": before-hook-creation
28+
rules:
29+
- apiGroups:
30+
- ""
31+
resources:
32+
- pods
33+
verbs:
34+
- get
35+
- list
36+
- patch
37+
---
38+
apiVersion: rbac.authorization.k8s.io/v1
39+
kind: RoleBinding
40+
metadata:
41+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
42+
labels:
43+
{{- include "osu-web-chart.labels" (dict "root" . "options" (dict "component" "upgrade-order")) | nindent 4 }}
44+
tier: wait-for-deploy
45+
annotations:
46+
"helm.sh/hook": pre-upgrade
47+
"helm.sh/hook-weight": "-5"
48+
"helm.sh/hook-delete-policy": before-hook-creation
49+
subjects:
50+
- kind: ServiceAccount
51+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
52+
apiGroup: ""
53+
roleRef:
54+
kind: Role
55+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
56+
apiGroup: ""
57+
---
58+
apiVersion: batch/v1
59+
kind: Job
60+
metadata:
61+
name: {{ include "osu-web-chart.fullname" . }}-upgrade-order
62+
labels:
63+
{{- include "osu-web-chart.labels" (dict "root" . "options" (dict "component" "upgrade-order")) | nindent 4 }}
64+
tier: wait-for-deploy
65+
annotations:
66+
"helm.sh/hook": pre-upgrade
67+
"helm.sh/hook-weight": "-5"
68+
"helm.sh/hook-delete-policy": before-hook-creation
69+
spec:
70+
template:
71+
spec:
72+
restartPolicy: Never
73+
serviceAccountName: {{ include "osu-web-chart.fullname" . }}-upgrade-order
74+
securityContext:
75+
{{- toYaml .Values.upgradeOrderJob.podSecurityContext | nindent 8 }}
76+
containers:
77+
- name: kubectl
78+
securityContext:
79+
{{- toYaml .Values.upgradeOrderJob.securityContext | nindent 12 }}
80+
image: {{ .Values.upgradeOrderJob.image }}
81+
{{- with .Values.upgradeOrderJob.imagePullPolicy }}
82+
imagePullPolicy: {{ . }}
83+
{{- end }}
84+
command:
85+
- /bin/bash
86+
- -c
87+
- |
88+
set -e
89+
90+
POD_TIMESTAMPS=$(
91+
kubectl get pods --selector=app.kubernetes.io/instance={{ .Release.Name }} -o json \
92+
| jq -r '.items[] | "\(.metadata.name) \(.metadata.creationTimestamp | fromdateiso8601)"'
93+
)
94+
95+
echo "$POD_TIMESTAMPS" | while read -r pod timestamp; do
96+
kubectl annotate --overwrite pod/"$pod" controller.kubernetes.io/pod-deletion-cost="$timestamp"
97+
done
98+
resources:
99+
{{- toYaml (.Values.upgradeOrderJob.resources | default .Values.resources) | nindent 12 }}
100+
{{- with .Values.nodeSelector }}
101+
nodeSelector:
102+
{{- toYaml . | nindent 12 }}
103+
{{- end }}
104+
{{- with .Values.tolerations }}
105+
tolerations:
106+
{{- toYaml . | nindent 12 }}
107+
{{- end }}
108+
{{- end -}}

osu/osu-web/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,14 @@ assets:
538538
securityContext:
539539
runAsUser: 1001
540540
runAsGroup: 1001
541+
542+
upgradeOrderJob:
543+
enabled: false
544+
image: bitnamisecure/kubectl:latest
545+
imagePullPolicy: IfNotPresent
546+
resources:
547+
requests:
548+
cpu: 10m
549+
memory: 64Mi
550+
limits:
551+
memory: 128Mi

0 commit comments

Comments
 (0)