Skip to content

Commit 9cadcde

Browse files
committed
Add taintmanager
1 parent 0731e7d commit 9cadcde

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 }}
@@ -172,6 +202,34 @@ spec:
172202
{{- . | toYaml | nindent 12 }}
173203
{{- end }}
174204
{{- end }}
205+
{{- if .Values.prePuller.taintmanager.enabled }}
206+
{{- $taint := first .Values.prePuller.taintmanager.tolerations }}
207+
- name: taintmanager-removing
208+
image: {{ .Values.prePuller.taintmanager.image.name }}:{{ .Values.prePuller.taintmanager.image.tag }}
209+
command:
210+
- /taintmanager
211+
- -remove
212+
- {{ $taint.key }}:{{ $taint.effect }}
213+
env:
214+
- name: GODEBUG
215+
value: x509sha1=1
216+
- name: MY_POD_NAME
217+
valueFrom:
218+
fieldRef:
219+
fieldPath: metadata.name
220+
- name: MY_NODE_NAME
221+
valueFrom:
222+
fieldRef:
223+
fieldPath: spec.nodeName
224+
{{- with .Values.prePuller.resources }}
225+
resources:
226+
{{- . | toYaml | nindent 12 }}
227+
{{- end }}
228+
{{- with .Values.prePuller.containerSecurityContext }}
229+
securityContext:
230+
{{- . | toYaml | nindent 12 }}
231+
{{- end }}
232+
{{- end }}
175233
containers:
176234
- name: pause
177235
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
@@ -609,6 +609,17 @@ prePuller:
609609
annotations: {}
610610
continuous:
611611
enabled: true
612+
taintmanager:
613+
enabled: true
614+
image:
615+
name: lthub/taintmanager
616+
tag: master
617+
# taint/tolerations used for preventing user pods being scheduled while user image is being pulled
618+
# only first element in the list is being used
619+
tolerations:
620+
- key: hub.jupyter.org/imagepulling
621+
operator: Exists
622+
effect: NoExecute
612623
pullProfileListImages: true
613624
extraImages: {}
614625
pause:

0 commit comments

Comments
 (0)