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

chore(slurmctld): charm maintained cgroup config #48

Merged
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
6 changes: 1 addition & 5 deletions charms/slurmctld/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ config:

cgroup-parameters:
type: string
default: |
ConstrainCores=yes
ConstrainDevices=yes
ConstrainRAMSpace=yes
ConstrainSwapSpace=yes
default: ""
description: |
User supplied configuration for `cgroup.conf`.

Expand Down
28 changes: 22 additions & 6 deletions charms/slurmctld/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import subprocess
from typing import Any, Dict, List, Optional, Union

from constants import CHARM_MAINTAINED_SLURM_CONF_PARAMETERS, PEER_RELATION
from constants import (
CHARM_MAINTAINED_CGROUP_CONF_PARAMETERS,
CHARM_MAINTAINED_SLURM_CONF_PARAMETERS,
PEER_RELATION,
)
from exceptions import IngressAddressUnavailableError
from interface_slurmd import (
PartitionAvailableEvent,
Expand Down Expand Up @@ -235,11 +239,12 @@ def _on_write_slurm_conf(
self._slurmctld.service.disable()
self._slurmctld.config.dump(slurm_config)

# Write out any user_supplied_cgroup_parameters to /etc/slurm/cgroup.conf.
if user_supplied_cgroup_parameters := self.config.get("cgroup-parameters", ""):
self._slurmctld.cgroup.dump(
CgroupConfig.from_str(str(user_supplied_cgroup_parameters))
)
# Write out any cgroup parameters to /etc/slurm/cgroup.conf.
if not is_container():
cgroup_config = CHARM_MAINTAINED_CGROUP_CONF_PARAMETERS
if user_supplied_cgroup_params := self._get_user_supplied_cgroup_parameters():
cgroup_config.update(user_supplied_cgroup_params)
self._slurmctld.cgroup.dump(CgroupConfig(**cgroup_config))

self._slurmctld.service.enable()
self._slurmctld.scontrol("reconfigure")
Expand Down Expand Up @@ -329,6 +334,17 @@ def _get_user_supplied_parameters(self) -> Dict[Any, Any]:
}
return user_supplied_parameters

def _get_user_supplied_cgroup_parameters(self) -> Dict[Any, Any]:
"""Gather, parse, and return the user supplied cgroup parameters."""
user_supplied_cgroup_parameters = {}
if custom_cgroup_config := self.config.get("cgroup-parameters"):
user_supplied_cgroup_parameters = {
line.split("=")[0]: line.split("=", 1)[1]
for line in str(custom_cgroup_config).split("\n")
if not line.startswith("#") and line.strip() != ""
}
return user_supplied_cgroup_parameters

def _get_new_node_names_from_slurm_config(
self, slurm_config: SlurmConfig
) -> List[Optional[str]]:
Expand Down
7 changes: 7 additions & 0 deletions charms/slurmctld/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

PEER_RELATION = "slurmctld-peer"

CHARM_MAINTAINED_CGROUP_CONF_PARAMETERS = {
"ConstrainCores": "yes",
"ConstrainDevices": "yes",
"ConstrainRAMSpace": "yes",
"ConstrainSwapSpace": "yes",
}

CHARM_MAINTAINED_SLURM_CONF_PARAMETERS = {
"AuthAltParameters": {"jwt_key": "/var/lib/slurm/checkpoint/jwt_hs256.key"},
"AuthAltTypes": ["auth/jwt"],
Expand Down