Skip to content
Open
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
19 changes: 19 additions & 0 deletions helm/nodesets/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ customInitContainers:
{{- end }}
{{- end -}}

{{/* Name of the slurm-scripts ConfigMap. Matches slurm-cluster chart, including its default cluster name. */}}
{{- define "nodesets.slurmScriptsCMName" -}}
{{- if $.Values.slurmScriptsConfigMapName -}}
{{- $.Values.slurmScriptsConfigMapName -}}
{{- else -}}
{{- printf "%s-slurm-scripts" (default "helm-slurm-cluster" $.Values.clusterName | trunc 63 | trimSuffix "-") -}}
{{- end -}}
{{- end -}}

{{/* True if list has an entry with the given name or mountPath. */}}
{{- define "nodesets.hasMount" -}}
{{- $found := false -}}
{{- $path := .path | default "" -}}
{{- range .list }}
{{- if or (eq .name $.name) (and $path .mountPath (eq (clean .mountPath) (clean $path))) }}{{ $found = true }}{{- end }}
{{- end -}}
{{- $found -}}
{{- end -}}

{{/* Construct container gpu resource from GPU spec ([0]) and GPU resource spec ([1]) */}}
{{- define "nodesets.resource.gpuFrom" -}}
{{- $gpuSpec := (index . 0) | default dict -}}
Expand Down
30 changes: 28 additions & 2 deletions helm/nodesets/templates/nodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,40 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}

{{- with (.jailSubMounts | default list) }}
{{- $slurmScriptsCMName := include "nodesets.slurmScriptsCMName" $ }}
{{- $jailSubMounts := .jailSubMounts | default list }}
{{- $customVolumeMounts := .customVolumeMounts | default list }}
{{- $injectJailSlurmScripts := not (eq "true" (include "nodesets.hasMount" (dict "list" $jailSubMounts "name" "slurm-scripts-jail" "path" "/opt/slurm_scripts"))) }}
{{- $injectCustomSlurmScripts := not (eq "true" (include "nodesets.hasMount" (dict "list" $customVolumeMounts "name" "slurm-scripts" "path" "/opt/slurm_scripts"))) }}

{{- if or $injectJailSlurmScripts $jailSubMounts }}
jailSubMounts:
{{- if $injectJailSlurmScripts }}
- name: slurm-scripts-jail
mountPath: /opt/slurm_scripts
volumeSource:
configMap:
name: {{ $slurmScriptsCMName | quote }}
defaultMode: 0755
{{- end }}
{{- with $jailSubMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}

{{- with (.customVolumeMounts | default list) }}
{{- if or $injectCustomSlurmScripts $customVolumeMounts }}
customVolumeMounts:
{{- if $injectCustomSlurmScripts }}
- name: slurm-scripts
mountPath: /opt/slurm_scripts
volumeSource:
configMap:
name: {{ $slurmScriptsCMName | quote }}
defaultMode: 0755
{{- end }}
{{- with $customVolumeMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}

{{- with (.persistentVolumeClaimRetentionPolicy | default dict) }}
Expand Down
160 changes: 160 additions & 0 deletions helm/nodesets/tests/slurm_scripts_mount_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
suite: test slurm-scripts mount injection
templates:
- templates/nodeset.yaml
set:
nodesets:
- &worker
name: worker
slurmd: &slurmd
resources: {cpu: "1", memory: 1Gi}
volumes:
spool: {emptyDir: {}}
jail: {emptyDir: {}}
munge:
resources: {cpu: 100m, memory: 128Mi}
tests:
- it: should inject both mounts with the cluster-derived ConfigMap name
set:
clusterName: my-cluster
asserts:
- equal:
path: spec.slurmd.volumes.jailSubMounts[0]
value:
name: slurm-scripts-jail
mountPath: /opt/slurm_scripts
volumeSource:
configMap: {name: my-cluster-slurm-scripts, defaultMode: 493}
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0]
value:
name: slurm-scripts
mountPath: /opt/slurm_scripts
volumeSource:
configMap: {name: my-cluster-slurm-scripts, defaultMode: 493}

- it: should not inject mounts that already exist with the same name
set:
clusterName: my-cluster
nodesets:
- <<: *worker
slurmd:
<<: *slurmd
volumes:
spool: {emptyDir: {}}
jail: {emptyDir: {}}
jailSubMounts:
- {name: slurm-scripts-jail, mountPath: /somewhere/else, volumeSource: {emptyDir: {}}}
customVolumeMounts:
- {name: slurm-scripts, mountPath: /elsewhere, volumeSource: {emptyDir: {}}}
asserts:
- lengthEqual:
path: spec.slurmd.volumes.jailSubMounts
count: 1
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].mountPath
value: /somewhere/else
- lengthEqual:
path: spec.slurmd.volumes.customVolumeMounts
count: 1
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].mountPath
value: /elsewhere

- it: should not inject mounts that use another name but the same mountPath
set:
clusterName: my-cluster
nodesets:
- <<: *worker
slurmd:
<<: *slurmd
volumes:
spool: {emptyDir: {}}
jail: {emptyDir: {}}
jailSubMounts:
- {name: my-jail-scripts, mountPath: /opt/slurm_scripts/, volumeSource: {emptyDir: {}}}
customVolumeMounts:
- {name: my-scripts, mountPath: /opt/./slurm_scripts//, volumeSource: {emptyDir: {}}}
asserts:
- lengthEqual:
path: spec.slurmd.volumes.jailSubMounts
count: 1
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].name
value: my-jail-scripts
- lengthEqual:
path: spec.slurmd.volumes.customVolumeMounts
count: 1
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].name
value: my-scripts

- it: should inject mounts next to user mounts on unrelated paths
set:
clusterName: my-cluster
nodesets:
- <<: *worker
slurmd:
<<: *slurmd
volumes:
spool: {emptyDir: {}}
jail: {emptyDir: {}}
customVolumeMounts:
- {name: data, mountPath: /opt/slurm_scripts_extra, volumeSource: {emptyDir: {}}}
asserts:
- lengthEqual:
path: spec.slurmd.volumes.customVolumeMounts
count: 2
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].name
value: slurm-scripts
- equal:
path: spec.slurmd.volumes.customVolumeMounts[1].name
value: data

- it: should fall back to the slurm-cluster default name when clusterName is empty
asserts:
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].volumeSource.configMap.name
value: helm-slurm-cluster-slurm-scripts
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.configMap.name
value: helm-slurm-cluster-slurm-scripts

- it: should use an explicit slurmScriptsConfigMapName
set:
clusterName: my-cluster
slurmScriptsConfigMapName: custom-scripts
asserts:
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].volumeSource.configMap.name
value: custom-scripts
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.configMap.name
value: custom-scripts

- it: should use an explicit slurmScriptsConfigMapName with empty clusterName
set:
slurmScriptsConfigMapName: custom-scripts
asserts:
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.configMap.name
value: custom-scripts

- it: should truncate a long clusterName like the slurm-cluster chart
set:
clusterName: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbb
asserts:
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].volumeSource.configMap.name
value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-slurm-scripts
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.configMap.name
value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-slurm-scripts

- it: should truncate a long clusterName without a trailing dash
set:
clusterName: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
asserts:
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.configMap.name
value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-slurm-scripts
20 changes: 10 additions & 10 deletions helm/nodesets/tests/volumes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ tests:
- isNotEmpty:
path: spec.slurmd.volumes.jailSubMounts
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].name
path: spec.slurmd.volumes.jailSubMounts[1].name
value: "tmp"
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].mountPath
path: spec.slurmd.volumes.jailSubMounts[1].mountPath
value: "/tmp"
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].subPath
path: spec.slurmd.volumes.jailSubMounts[1].subPath
value: "tmp"
- equal:
path: spec.slurmd.volumes.jailSubMounts[0].readOnly
path: spec.slurmd.volumes.jailSubMounts[1].readOnly
value: false
- exists:
path: spec.slurmd.volumes.jailSubMounts[0].volumeSource.emptyDir
path: spec.slurmd.volumes.jailSubMounts[1].volumeSource.emptyDir

- it: should configure custom mounts correctly
set:
Expand Down Expand Up @@ -136,19 +136,19 @@ tests:
- isNotEmpty:
path: spec.slurmd.volumes.customVolumeMounts
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].name
path: spec.slurmd.volumes.customVolumeMounts[1].name
value: "tmp"
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].mountPath
path: spec.slurmd.volumes.customVolumeMounts[1].mountPath
value: "/tmp"
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].subPath
path: spec.slurmd.volumes.customVolumeMounts[1].subPath
value: "tmp"
- equal:
path: spec.slurmd.volumes.customVolumeMounts[0].readOnly
path: spec.slurmd.volumes.customVolumeMounts[1].readOnly
value: false
- exists:
path: spec.slurmd.volumes.customVolumeMounts[0].volumeSource.emptyDir
path: spec.slurmd.volumes.customVolumeMounts[1].volumeSource.emptyDir

- it: should configure security context correctly
set:
Expand Down
2 changes: 2 additions & 0 deletions helm/nodesets/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
nameOverride: ""
fullnameOverride: ""
clusterName: ""
# Name of the slurm-scripts ConfigMap. Defaults to "<clusterName>-slurm-scripts" ("helm-slurm-cluster" if clusterName is empty).
slurmScriptsConfigMapName: ""
# Priority Classes configuration
# Define priority classes that can be used by NodeSets
priorityClasses:
Expand Down
14 changes: 14 additions & 0 deletions helm/slurm-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,22 @@

{{/* Name of the slurm-scripts ConfigMap */}}
{{- define "slurm-cluster.slurmScriptsCMName" -}}
{{- if .Values.slurmScriptsConfigMapName -}}
{{- .Values.slurmScriptsConfigMapName -}}
{{- else -}}
{{- printf "%s-slurm-scripts" (include "slurm-cluster.name" .) -}}
{{- end -}}
{{- end -}}

{{/* True if list has an entry with the given name or mountPath. */}}
{{- define "slurm-cluster.hasMount" -}}
{{- $found := false -}}
{{- $path := .path | default "" -}}
{{- range .list }}
{{- if or (eq .name $.name) (and $path .mountPath (eq (clean .mountPath) (clean $path))) }}{{ $found = true }}{{- end }}
{{- end -}}
{{- $found -}}
{{- end -}}

{{- define "validateAccountingConfig" -}}
{{- if .Values.slurmNodes.accounting.enabled -}}
Expand Down
6 changes: 6 additions & 0 deletions helm/slurm-cluster/templates/slurm-cluster-cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ spec:
{{- end }}
{{- end }}
volumeSources:
{{- if not (eq "true" (include "slurm-cluster.hasMount" (dict "list" .Values.volumeSources "name" "slurm-scripts"))) }}
- name: slurm-scripts
configMap:
name: {{ include "slurm-cluster.slurmScriptsCMName" . }}
defaultMode: 0755
{{- end }}
{{- range .Values.volumeSources }}
- name: {{ .name | quote }}
{{- omit . "name" "createPVC" "storageClassName" "size" | toYaml | nindent 6 }}
Expand Down Expand Up @@ -480,12 +482,16 @@ spec:
jailSubMounts:
{{- default list .Values.slurmNodes.login.volumes.jailSubMounts | toYaml | nindent 10 }}
customMounts:
{{- if not (eq "true" (include "slurm-cluster.hasMount" (dict "list" .Values.slurmNodes.login.volumes.customMounts "name" "slurm-scripts" "path" "/opt/slurm_scripts"))) }}
- name: slurm-scripts
mountPath: /opt/slurm_scripts/
volumeSourceName: slurm-scripts
{{- end }}
{{- if not (eq "true" (include "slurm-cluster.hasMount" (dict "list" .Values.slurmNodes.login.volumes.customMounts "name" "slurm-scripts-jail" "path" "/mnt/jail.upper/opt/slurm_scripts"))) }}
- name: slurm-scripts-jail
mountPath: /mnt/jail.upper/opt/slurm_scripts/
volumeSourceName: slurm-scripts
{{- end }}
{{- if .Values.slurmNodes.login.volumes.customMounts }}
{{- .Values.slurmNodes.login.volumes.customMounts | toYaml | nindent 10 }}
{{- end }}
Expand Down
Loading
Loading