Skip to content

Commit 98fe35a

Browse files
committed
Add taintmanager
1 parent 82cfdec commit 98fe35a

File tree

4 files changed

+108
-3
lines changed

4 files changed

+108
-3
lines changed

jupyterhub/templates/image-puller/_helpers-daemonset.tpl

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ spec:
5151
per node limit all k8s clusters have and have a higher priority
5252
than user-placeholder pods that could block an entire node.
5353
*/}}
54+
serviceAccount: taintmanager
55+
serviceAccountName: taintmanager
5456
{{- if .Values.scheduling.podPriority.enabled }}
5557
priorityClassName: {{ include "jupyterhub.image-puller-priority.fullname" . }}
5658
{{- end }}
5759
{{- with .Values.singleuser.nodeSelector }}
5860
nodeSelector:
5961
{{- . | toYaml | nindent 8 }}
6062
{{- end }}
61-
{{- with concat .Values.scheduling.userPods.tolerations .Values.singleuser.extraTolerations .Values.prePuller.extraTolerations }}
63+
{{- with concat .Values.scheduling.userPods.tolerations .Values.singleuser.extraTolerations .Values.prePuller.extraTolerations .Values.prePuller.taintmanager.tolerations }}
6264
tolerations:
6365
{{- . | toYaml | nindent 8 }}
6466
{{- end }}
@@ -70,11 +72,39 @@ spec:
7072
{{- include "jupyterhub.userNodeAffinityRequired" . | nindent 14 }}
7173
{{- end }}
7274
terminationGracePeriodSeconds: 0
73-
automountServiceAccountToken: false
75+
automountServiceAccountToken: true
7476
{{- with include "jupyterhub.imagePullSecrets" (dict "root" . "image" .Values.singleuser.image) }}
7577
imagePullSecrets: {{ . }}
7678
{{- end }}
7779
initContainers:
80+
{{- if .Values.prePuller.taintmanager.enabled }}
81+
{{- $taint := first .Values.prePuller.taintmanager.tolerations }}
82+
- name: taintmanager-adding
83+
image: {{ .Values.prePuller.taintmanager.image.name }}:{{ .Values.prePuller.taintmanager.image.tag }}
84+
command:
85+
- /taintmanager
86+
- -add
87+
- {{ $taint.key }}:{{ $taint.effect }}
88+
env:
89+
- name: GODEBUG
90+
value: x509sha1=1
91+
- name: MY_POD_NAME
92+
valueFrom:
93+
fieldRef:
94+
fieldPath: metadata.name
95+
- name: MY_NODE_NAME
96+
valueFrom:
97+
fieldRef:
98+
fieldPath: spec.nodeName
99+
{{- with .Values.prePuller.resources }}
100+
resources:
101+
{{- . | toYaml | nindent 12 }}
102+
{{- end }}
103+
{{- with .Values.prePuller.containerSecurityContext }}
104+
securityContext:
105+
{{- . | toYaml | nindent 12 }}
106+
{{- end }}
107+
{{- end }}
78108
{{- /* --- Conditionally pull an image all user pods will use in an initContainer --- */}}
79109
{{- $blockWithIptables := hasKey .Values.singleuser.cloudMetadata "enabled" | ternary (not .Values.singleuser.cloudMetadata.enabled) .Values.singleuser.cloudMetadata.blockWithIptables }}
80110
{{- if $blockWithIptables }}
@@ -200,6 +230,34 @@ spec:
200230
{{- . | toYaml | nindent 12 }}
201231
{{- end }}
202232
{{- end }}
233+
{{- if .Values.prePuller.taintmanager.enabled }}
234+
{{- $taint := first .Values.prePuller.taintmanager.tolerations }}
235+
- name: taintmanager-removing
236+
image: {{ .Values.prePuller.taintmanager.image.name }}:{{ .Values.prePuller.taintmanager.image.tag }}
237+
command:
238+
- /taintmanager
239+
- -remove
240+
- {{ $taint.key }}:{{ $taint.effect }}
241+
env:
242+
- name: GODEBUG
243+
value: x509sha1=1
244+
- name: MY_POD_NAME
245+
valueFrom:
246+
fieldRef:
247+
fieldPath: metadata.name
248+
- name: MY_NODE_NAME
249+
valueFrom:
250+
fieldRef:
251+
fieldPath: spec.nodeName
252+
{{- with .Values.prePuller.resources }}
253+
resources:
254+
{{- . | toYaml | nindent 12 }}
255+
{{- end }}
256+
{{- with .Values.prePuller.containerSecurityContext }}
257+
securityContext:
258+
{{- . | toYaml | nindent 12 }}
259+
{{- end }}
260+
{{- end }}
203261
containers:
204262
- name: pause
205263
image: {{ .Values.prePuller.pause.image.name }}:{{ .Values.prePuller.pause.image.tag }}

jupyterhub/templates/image-puller/rbac.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,40 @@ roleRef:
4242
name: {{ include "jupyterhub.hook-image-awaiter.fullname" . }}
4343
apiGroup: rbac.authorization.k8s.io
4444
{{- end }}
45+
{{- if .Values.prePuller.taintmanager.enabled }}
46+
---
47+
apiVersion: v1
48+
kind: ServiceAccount
49+
metadata:
50+
name: taintmanager
51+
namespace: "{{ .Release.Namespace }}"
52+
labels:
53+
{{- include "jupyterhub.labels" . | nindent 4 }}
54+
---
55+
apiVersion: rbac.authorization.k8s.io/v1
56+
kind: ClusterRole
57+
metadata:
58+
name: taintmanager
59+
labels:
60+
{{- include "jupyterhub.labels" . | nindent 4 }}
61+
rules:
62+
- apiGroups: [""] # "" indicates the core API group
63+
resources: ["nodes"]
64+
verbs: ["get", "update"]
65+
---
66+
apiVersion: rbac.authorization.k8s.io/v1
67+
kind: ClusterRoleBinding
68+
metadata:
69+
name: taintmanager
70+
labels:
71+
{{- include "jupyterhub.labels" . | nindent 4 }}
72+
subjects:
73+
- kind: ServiceAccount
74+
name: taintmanager
75+
namespace: "{{ .Release.Namespace }}"
76+
roleRef:
77+
kind: ClusterRole
78+
name: taintmanager
79+
apiGroup: rbac.authorization.k8s.io
80+
{{- end }}
4581
{{- end }}

jupyterhub/templates/scheduling/user-placeholder/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ spec:
4747
nodeSelector:
4848
{{- . | toYaml | nindent 8 }}
4949
{{- end }}
50-
{{- with concat .Values.scheduling.userPods.tolerations .Values.singleuser.extraTolerations }}
50+
{{- with concat .Values.scheduling.userPods.tolerations .Values.singleuser.extraTolerations .Values.prePuller.taintmanager.tolerations }}
5151
tolerations:
5252
{{- . | toYaml | nindent 8 }}
5353
{{- end }}

jupyterhub/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,17 @@ prePuller:
623623
annotations: {}
624624
continuous:
625625
enabled: true
626+
taintmanager:
627+
enabled: true
628+
image:
629+
name: lthub/taintmanager
630+
tag: master
631+
# taint/tolerations used for preventing user pods being scheduled while user image is being pulled
632+
# only first element in the list is being used
633+
tolerations:
634+
- key: hub.jupyter.org/imagepulling
635+
operator: Exists
636+
effect: NoExecute
626637
pullProfileListImages: true
627638
extraImages: {}
628639
pause:

0 commit comments

Comments
 (0)