Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chart): add session tolerations, affinity, nodeSelector #806

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "[]"))