Skip to content

Commit 050c431

Browse files
authored
Merge pull request #2224 from consideRatio/pr/add-hub.lifecycle-configuration
Add hub.lifecycle configuration (for postStart/preStop lifecycle hooks in hub pod)
2 parents 720afa7 + 365cf93 commit 050c431

File tree

4 files changed

+89
-68
lines changed

4 files changed

+89
-68
lines changed

jupyterhub/schema.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,19 @@ properties:
10921092
description: |
10931093
A k8s native specification of resources, see [the
10941094
documentation](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#resourcerequirements-v1-core).
1095+
lifecycle: &lifecycle-spec
1096+
type: object
1097+
additionalProperties: false
1098+
description: |
1099+
A k8s native specification of lifecycle hooks on the container, see [the
1100+
documentation](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#lifecycle-v1-core).
1101+
properties:
1102+
postStart:
1103+
type: object
1104+
additionalProperties: true
1105+
preStop:
1106+
type: object
1107+
additionalProperties: true
10951108
services:
10961109
type: object
10971110
additionalProperties: true
@@ -1855,6 +1868,13 @@ properties:
18551868
type: object
18561869
additionalProperties: false
18571870
description: *kubespawner-native-config-description
1871+
properties:
1872+
postStart:
1873+
type: object
1874+
additionalProperties: true
1875+
preStop:
1876+
type: object
1877+
additionalProperties: true
18581878
networkTools:
18591879
type: object
18601880
additionalProperties: false

jupyterhub/templates/hub/deployment.yaml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
{{- . | toYaml | trimSuffix "\n" | nindent 8 }}
2424
{{- end }}
2525
annotations:
26-
# This lets us autorestart when the secret changes!
26+
{{- /* This lets us autorestart when the secret changes! */}}
2727
checksum/config-map: {{ include (print .Template.BasePath "/hub/configmap.yaml") . | sha256sum }}
2828
checksum/secret: {{ include (print .Template.BasePath "/hub/secret.yaml") . | sha256sum }}
2929
{{- with .Values.hub.annotations }}
@@ -111,13 +111,13 @@ spec:
111111
{{- if .Values.debug.enabled }}
112112
- --debug
113113
{{- end }}
114-
{{- /*
115-
We want to do automatic upgrades for sqlite-pvc by default, but
116-
allow users to opt out of that if they want. Users using their own
117-
db need to 'opt in' Go Templates treat nil and "" and false as
118-
'false', making this code complex. We can probably make this a
119-
one-liner, but doing combinations of boolean vars in go templates is
120-
very inelegant & hard to reason about.
114+
{{- /* NOTE:
115+
We want to do automatic upgrades for sqlite-pvc by default, but
116+
allow users to opt out of that if they want. Users using their own
117+
db need to 'opt in' Go Templates treat nil and "" and false as
118+
'false', making this code complex. We can probably make this a
119+
one-liner, but doing combinations of boolean vars in go templates
120+
is very inelegant & hard to reason about.
121121
*/}}
122122
{{- $upgradeType := typeOf .Values.hub.db.upgrade }}
123123
{{- if eq $upgradeType "bool" }}
@@ -179,6 +179,10 @@ spec:
179179
securityContext:
180180
{{- $securityContext | toYaml | trimSuffix "\n" | nindent 12 }}
181181
{{- end }}
182+
{{- with .Values.hub.lifecycle }}
183+
lifecycle:
184+
{{- . | toYaml | trimSuffix "\n" | nindent 12 }}
185+
{{- end }}
182186
env:
183187
- name: PYTHONUNBUFFERED
184188
value: "1"
@@ -191,9 +195,12 @@ spec:
191195
- name: CONFIGPROXY_AUTH_TOKEN
192196
valueFrom:
193197
secretKeyRef:
194-
# NOTE: References the chart managed k8s Secret even if
195-
# hub.existingSecret is specified to avoid using the
196-
# lookup function on the user managed k8s Secret.
198+
{{- /* NOTE:
199+
References the chart managed k8s Secret even if
200+
hub.existingSecret is specified to avoid using the lookup
201+
function on the user managed k8s Secret which is assumed to
202+
not be possible.
203+
*/}}
197204
name: {{ include "jupyterhub.hub.fullname" . }}
198205
key: hub.config.ConfigurableHTTPProxy.auth_token
199206
{{- with .Values.hub.extraEnv }}
@@ -203,13 +210,13 @@ spec:
203210
- name: http
204211
containerPort: 8081
205212
{{- if .Values.hub.livenessProbe.enabled }}
206-
# livenessProbe notes:
207-
# We don't know how long hub database upgrades could take
208-
# so having a liveness probe could be a bit risky unless we put
209-
# a initialDelaySeconds value with long enough margin for that
210-
# to not be an issue. If it is too short, we could end up aborting
211-
# database upgrades midway or ending up in an infinite restart
212-
# loop.
213+
{{- /* NOTE:
214+
We don't know how long hub database upgrades could take so having a
215+
liveness probe could be a bit risky unless we put a
216+
initialDelaySeconds value with long enough margin for that to not be
217+
an issue. If it is too short, we could end up aborting database
218+
upgrades midway or ending up in an infinite restart loop.
219+
*/}}
213220
livenessProbe:
214221
initialDelaySeconds: {{ .Values.hub.livenessProbe.initialDelaySeconds }}
215222
periodSeconds: {{ .Values.hub.livenessProbe.periodSeconds }}

jupyterhub/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ hub:
8888
runAsUser: 1000
8989
runAsGroup: 1000
9090
allowPrivilegeEscalation: false
91+
lifecycle: {}
9192
services: {}
9293
pdb:
9394
enabled: false

tools/templates/lint-and-validate-values.yaml

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,23 @@ hub:
7474
deploymentStrategy:
7575
type: Recreate
7676
rollingUpdate:
77+
labels: &labels
78+
mock-label1-key: mock-label1-value
79+
mock-label2-key: mock-label2-value
80+
annotations: &annotations
81+
mock-annotation1-key: mock-annotation1-value
82+
mock-annotation2-key: mock-annotation2-value
7783
db:
7884
type: sqlite-pvc
7985
upgrade:
8086
pvc:
81-
annotations:
82-
mock-annotation: mock
83-
selector:
84-
matchLabels:
85-
mock-selector: mock
87+
annotations: *annotations
8688
accessModes:
8789
- ReadWriteOnce
8890
storage: 1Gi
8991
subPath: /mock
9092
storageClassName: custom-storage-class
9193
url: custom-db-url
92-
labels:
93-
mock: mock
94-
annotations:
95-
mock: mock
9694
image:
9795
name: dummy-name
9896
tag: dummy-tag
@@ -111,7 +109,7 @@ hub:
111109
c.Spawner.cmd = 'mock'
112110
extraConfigMap:
113111
mock.entry: mock-config-map-entry
114-
extraEnv:
112+
extraEnv: &extraEnv
115113
IGNORED_KEY_NAME:
116114
name: MOCK_ENV_VAR_NAME1
117115
value: MOCK_ENV_VAR_VALUE1
@@ -120,10 +118,26 @@ hub:
120118
extraContainers: []
121119
extraVolumes: []
122120
extraVolumeMounts: []
123-
resources:
121+
resources: &resources
124122
requests:
125123
cpu: 100m
126124
memory: 512Mi
125+
limits:
126+
cpu: 200m
127+
memory: 1Gi
128+
lifecycle: &lifecycle
129+
postStart:
130+
exec:
131+
command:
132+
- "/bin/sh"
133+
- "-c"
134+
- "echo Hello from the postStart handler >> /usr/share/message"
135+
preStop:
136+
exec:
137+
command:
138+
- "/bin/sh"
139+
- "-c"
140+
- "echo Hello from the preStart handler >> /usr/share/message"
127141
services:
128142
tests:
129143
apiToken: mocked-api-token
@@ -158,25 +172,19 @@ proxy:
158172
port: 22
159173
targetPort: ssh
160174
type: LoadBalancer
161-
labels:
162-
MOCK_PROXY_ENV: mock
163-
annotations:
164-
hub.jupyter.org/mock-proxy-annotation: mock
175+
labels: *labels
176+
annotations: *annotations
165177
nodePorts:
166178
http:
167179
https:
168180
chp:
169181
extraCommandLineFlags:
170182
- "--auto-rewrite"
171183
- "--mock-flag {{ .Values.proxy.chp.resources.requests.memory }}"
172-
resources:
173-
requests:
174-
cpu: 100m
175-
memory: 512Mi
184+
resources: *resources
176185
defaultTarget: http://dummy.local/hello
177186
errorTarget: http://dummy.local/error
178-
extraEnv:
179-
MOCK_ENV: mock
187+
extraEnv: *extraEnv
180188
nodeSelector:
181189
node-type: mock
182190
tolerations:
@@ -200,17 +208,9 @@ proxy:
200208
extraPorts:
201209
- name: ssh
202210
containerPort: 8022
203-
labels:
204-
hub.jupyter.org/test-label: mock
205-
resources:
206-
requests:
207-
cpu: 200m
208-
memory: 512Mi
209-
limits:
210-
cpu: 200m
211-
memory: 1Gi
212-
extraEnv:
213-
LEGO_CA_CERTIFICATES: /etc/pebble/root-cert.pem
211+
labels: *labels
212+
resources: *resources
213+
extraEnv: *extraEnv
214214
nodeSelector:
215215
node-type: mock
216216
tolerations:
@@ -231,15 +231,8 @@ proxy:
231231
maxUnavailable: null
232232
minAvailable: 1
233233
secretSync:
234-
resources:
235-
requests:
236-
cpu: 100m
237-
memory: 128Mi
238-
limits:
239-
cpu: 200m
240-
memory: 1Gi
241-
labels:
242-
mock-proxy-label: mock
234+
resources: *resources
235+
labels: *labels
243236
https:
244237
enabled: true
245238
type: letsencrypt
@@ -334,9 +327,9 @@ singleuser:
334327
interNamespaceAccessLabels: ignore
335328
allowedIngressPorts: []
336329
events: true
337-
extraLabels: {}
338-
extraEnv: {}
339-
lifecycleHooks: {}
330+
extraLabels: *labels
331+
extraEnv: *extraEnv
332+
lifecycleHooks: *lifecycle
340333
initContainers:
341334
- name: mock-init-container-name
342335
image: mock-init-container-image
@@ -350,8 +343,7 @@ singleuser:
350343
serviceAccountName:
351344
storage:
352345
type: dynamic
353-
extraLabels:
354-
mock-label: mock-value
346+
extraLabels: *labels
355347
extraVolumes: []
356348
extraVolumeMounts: []
357349
static:
@@ -407,7 +399,7 @@ scheduling:
407399
userPlaceholder:
408400
enabled: true
409401
replicas: 1
410-
resources: {}
402+
resources: *resources
411403
corePods:
412404
tolerations:
413405
- key: mock-taint-key-corePods
@@ -452,8 +444,7 @@ prePuller:
452444

453445
ingress:
454446
enabled: true
455-
annotations:
456-
mock: mock
447+
annotations: *annotations
457448
hosts:
458449
- mocked1.domain.name
459450
- mocked2.domain.name
@@ -474,7 +465,9 @@ cull:
474465
debug:
475466
enabled: true
476467

477-
global: {}
468+
global:
469+
whatever:
470+
this-should-be-accepted: true
478471

479472
custom:
480473
myCustomStuff: [hello]

0 commit comments

Comments
 (0)