Skip to content

Commit

Permalink
feat(chart): add session tolerations, affinity, nodeSelector (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Nov 15, 2021
1 parent 30df71b commit 49a2d54
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
16 changes: 15 additions & 1 deletion helm-chart/renku-notebooks/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ spec:
- name: SENTRY_ENV
value: {{ .Values.sentry.env | quote }}
{{ end }}

{{- with .Values.sessionNodeSelector }}
- name: SESSION_NODE_SELECTOR
value: |
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .Values.sessionAffinity }}
- name: SESSION_AFFINITY
value: |
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .Values.sessionTolerations }}
- name: SESSION_TOLERATIONS
value: |
{{- toYaml . | nindent 16 }}
{{- end }}
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
Expand Down
15 changes: 15 additions & 0 deletions helm-chart/renku-notebooks/templates/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
{{- with $.Values.sessionNodeSelector }}
- name: SESSION_NODE_SELECTOR
value: |
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $.Values.sessionAffinity }}
- name: SESSION_AFFINITY
value: |
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $.Values.sessionTolerations }}
- name: SESSION_TOLERATIONS
value: |
{{- toYaml . | nindent 12 }}
{{- end }}
command:
- pipenv
- run
Expand Down
6 changes: 6 additions & 0 deletions helm-chart/renku-notebooks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ sessionIngress:
nginx.ingress.kubernetes.io/proxy-buffer-size: 8k
nginx.ingress.kubernetes.io/proxy-request-buffering: "off"

## Setup node selector, tolerations and node affinities for user sessions that are launched
## by the notebook service.
sessionNodeSelector: {}
sessionTolerations: []
sessionAffinity: {}

## Default server options - these will be provided to the user in the UI
## Note that requests are also limits, i.e. a user's jupyter kernel
## that exceeds the requested memory limit will be terminated/restarted.
Expand Down
34 changes: 25 additions & 9 deletions renku_notebooks/api/classes/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ def _get_session_manifest(self):
+ "projectName": self.gl_project.path.lower(),
f"{current_app.config['RENKU_ANNOTATION_PREFIX']}requested-image": self.image,
}
tolerations = [
{
"key": f"{current_app.config['RENKU_ANNOTATION_PREFIX']}dedicated",
"operator": "Equal",
"value": "user",
"effect": "NoSchedule",
}
]
# Add image pull secret if image is private
if self.is_image_private:
image_pull_secret_name = self.server_name + "-image-secret"
Expand Down Expand Up @@ -565,7 +557,31 @@ def _get_session_manifest(self):
{
"op": "add",
"path": "/statefulset/spec/template/spec/tolerations",
"value": tolerations,
"value": current_app.config["SESSION_TOLERATIONS"],
}
],
}
)
patches.append(
{
"type": "application/json-patch+json",
"patch": [
{
"op": "add",
"path": "/statefulset/spec/template/spec/affinity",
"value": current_app.config["SESSION_AFFINITY"],
}
],
}
)
patches.append(
{
"type": "application/json-patch+json",
"patch": [
{
"op": "add",
"path": "/statefulset/spec/template/spec/nodeSelector",
"value": current_app.config["SESSION_NODE_SELECTOR"],
}
],
}
Expand Down
4 changes: 4 additions & 0 deletions renku_notebooks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@
CULLING_ANONYMOUS_IDLE_SESSIONS_THRESHOLD_SECONDS = int(
os.getenv("CULLING_ANONYMOUS_IDLE_SESSIONS_THRESHOLD_SECONDS", 43200)
)

SESSION_NODE_SELECTOR = safe_load(os.environ.get("SESSION_NODE_SELECTOR", "{}"))
SESSION_AFFINITY = safe_load(os.environ.get("SESSION_AFFINITY", "{}"))
SESSION_TOLERATIONS = safe_load(os.environ.get("SESSION_TOLERATIONS", "[]"))

0 comments on commit 49a2d54

Please sign in to comment.