forked from jupyterhub/zero-to-jupyterhub-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for configuring
extraTolerations
and extra...Affinity
For use with the kubespawner features introduced in jupyterhub/kubespawner#205.
- Loading branch information
1 parent
dd7ba95
commit 194a66c
Showing
8 changed files
with
276 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
jupyterhub/templates/scheduling/_scheduling-helpers.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
{{- /* | ||
jupyterhub.prepareScope | ||
Requires the .podKind field. | ||
prepareScope sets fields on the scope to be used by the | ||
jupyterhub.tolerations and jupyterhub.affinity helm template functions | ||
below. | ||
*/}} | ||
{{- define "jupyterhub.prepareScope" -}} | ||
{{- /* Update the copied scope */}} | ||
{{- $dummy := set . "component" (include "jupyterhub.componentLabel" .) }} | ||
|
||
{{- if .podKind }} | ||
{{- if eq .podKind "core" -}} | ||
{{- $dummy := set . "matchNodePurpose" .Values.scheduling.corePods.nodeAffinity.matchNodePurpose }} | ||
{{- else if eq .podKind "user" -}} | ||
{{- $dummy := set . "matchNodePurpose" .Values.scheduling.userPods.nodeAffinity.matchNodePurpose }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
|
||
{{- /* Fetch relevant information */}} | ||
{{- $dummy := set . "tolerationsList" (include "jupyterhub.tolerationsList" .) }} | ||
{{- $dummy := set . "tolerations" (include "jupyterhub.tolerations" .) }} | ||
{{- $dummy := set . "hasTolerations" .tolerations }} | ||
|
||
{{- $dummy := set . "nodeAffinityRequired" (include "jupyterhub.nodeAffinityRequired" .) }} | ||
{{- $dummy := set . "podAffinityRequired" (include "jupyterhub.podAffinityRequired" .) }} | ||
{{- $dummy := set . "podAntiAffinityRequired" (include "jupyterhub.podAntiAffinityRequired" .) }} | ||
{{- $dummy := set . "nodeAffinityPreferred" (include "jupyterhub.nodeAffinityPreferred" .) }} | ||
{{- $dummy := set . "podAffinityPreferred" (include "jupyterhub.podAffinityPreferred" .) }} | ||
{{- $dummy := set . "podAntiAffinityPreferred" (include "jupyterhub.podAntiAffinityPreferred" .) }} | ||
{{- $dummy := set . "hasNodeAffinity" (or .nodeAffinityRequired .nodeAffinityPreferred) }} | ||
{{- $dummy := set . "hasPodAffinity" (or .podAffinityRequired .podAffinityPreferred) }} | ||
{{- $dummy := set . "hasPodAntiAffinity" (or .podAntiAffinityRequired .podAntiAffinityPreferred) }} | ||
{{- $dummy := set . "hasAffinity" (or .hasNodeAffinity .hasPodAffinity .hasPodAntiAffinity) }} | ||
{{- end }} | ||
|
||
|
||
|
||
{{- /* | ||
jupyterhub.tolerations | ||
Refactors the setting of the user pods tolerations field. | ||
*/}} | ||
{{- define "jupyterhub.tolerations" -}} | ||
{{- if .tolerationsList -}} | ||
tolerations: | ||
{{- .tolerationsList | nindent 2 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.tolerationsList" -}} | ||
{{- if eq .podKind "core" -}} | ||
{{- else if eq .podKind "user" -}} | ||
- key: hub.jupyter.org_dedicated | ||
operator: Equal | ||
value: user | ||
effect: NoSchedule | ||
{{- if .Values.singleuser.extraTolerations -}} | ||
{{- .Values.singleuser.extraTolerations | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
|
||
|
||
{{- define "jupyterhub.nodeAffinityRequired" -}} | ||
{{- if eq .matchNodePurpose "require" -}} | ||
- matchExpressions: | ||
- key: hub.jupyter.org/node-purpose | ||
operator: In | ||
values: [{{ .podKind }}] | ||
{{- end }} | ||
{{- if .Values.singleuser.extraNodeAffinity.required -}} | ||
{{- .Values.singleuser.extraNodeAffinity.required | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.nodeAffinityPreferred" -}} | ||
{{- if eq .matchNodePurpose "prefer" -}} | ||
- weight: 100 | ||
preference: | ||
matchExpressions: | ||
- key: hub.jupyter.org/node-purpose | ||
operator: In | ||
values: [{{ .podKind }}] | ||
{{- end }} | ||
{{- if .Values.singleuser.extraNodeAffinity.preferred -}} | ||
{{- .Values.singleuser.extraNodeAffinity.preferred | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.podAffinityRequired" -}} | ||
{{- if .Values.singleuser.extraPodAffinity.required }} | ||
{{- .Values.singleuser.extraPodAffinity.required | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.podAffinityPreferred" -}} | ||
{{- if .Values.scheduling.userPods.podAffinity.preferScheduleNextToRealUsers -}} | ||
- weight: 100 | ||
podAffinityTerm: | ||
labelSelector: | ||
matchExpressions: | ||
- key: component | ||
operator: In | ||
values: [singleuser-server] | ||
topologyKey: kubernetes.io/hostname | ||
{{- end }} | ||
{{- if .Values.singleuser.extraPodAffinity.preferred -}} | ||
{{- .Values.singleuser.extraPodAffinity.preferred | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.podAntiAffinityRequired" -}} | ||
{{- if .Values.singleuser.extraPodAntiAffinity.required -}} | ||
{{- .Values.singleuser.extraPodAntiAffinity.required | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "jupyterhub.podAntiAffinityPreferred" -}} | ||
{{- if eq .component "scheduler" -}} | ||
- weight: 100 | ||
podAffinityTerm: | ||
labelSelector: | ||
matchExpressions: | ||
- key: component | ||
operator: In | ||
values: [scheduler] | ||
topologyKey: kubernetes.io/hostname | ||
{{- end }} | ||
{{- if .Values.singleuser.extraPodAntiAffinity.preferred -}} | ||
{{- .Values.singleuser.extraPodAntiAffinity.preferred | toYaml | trimSuffix "\n" | nindent 0 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
|
||
|
||
{{- /* | ||
input: podKind | ||
*/}} | ||
{{- define "jupyterhub.affinity" -}} | ||
{{- /* | ||
HACK: Creating a copy of the scope to avoid modification of the scope passed | ||
to us. We will reference this copy from within the if statements in order to | ||
be able to set a variable outside the if statements local scope. | ||
*/}} | ||
{{- /* Render the affinity entry */}} | ||
{{- if .hasAffinity -}} | ||
affinity: | ||
{{- if .hasNodeAffinity }} | ||
nodeAffinity: | ||
{{- if .nodeAffinityRequired }} | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
{{- .nodeAffinityRequired | nindent 8 }} | ||
{{- end }} | ||
|
||
{{- if .nodeAffinityPreferred }} | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
{{- .nodeAffinityPreferred | nindent 6 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- if .hasPodAffinity }} | ||
podAffinity: | ||
{{- if .podAffinityRequired }} | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
{{- .podAffinityRequired | nindent 6 }} | ||
{{- end }} | ||
|
||
{{- if .podAffinityPreferred }} | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
{{- .podAffinityPreferred | nindent 6 }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- if .hasPodAntiAffinity }} | ||
podAntiAffinity: | ||
{{- if .podAntiAffinityRequired }} | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
{{- .podAntiAffinityRequired | nindent 6 }} | ||
{{- end }} | ||
|
||
{{- if .podAntiAffinityPreferred }} | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
{{- .podAntiAffinityPreferred | nindent 6 }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters