Skip to content

Commit

Permalink
chore(slurmctld): charm maintained cgroup config
Browse files Browse the repository at this point in the history
These changes move the cgroup config to the charm constants.py.
  • Loading branch information
jamesbeedy authored and NucciTheBoss committed Nov 27, 2024
1 parent 46b4f17 commit 274fc85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
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

0 comments on commit 274fc85

Please sign in to comment.