Skip to content

Commit

Permalink
chore(slurmctld): use peer relation for ingress ip
Browse files Browse the repository at this point in the history
These changes add a peer relation for the slurmctld charm
and replace using the slurmd interface to obtain the
ingress_address with the new slurmctld-peer relation.

The reason for this change is that we do not want to depend
on the existence of the slurmd relation in order to know our ip.

Using a peer relation we will always have resolvability so long
as juju knows the ip address of the unit.
  • Loading branch information
jamesbeedy committed Aug 20, 2024
1 parent a6a13db commit 240498a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions charms/slurmctld/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ requires:
slurmrestd:
interface: slurmrestd

peers:
slurmctld-peer:
interface: slurmctld-peer

assumes:
- juju

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

from constants import CHARM_MAINTAINED_SLURM_CONF_PARAMETERS, SLURM_CONF_PATH
from constants import CHARM_MAINTAINED_SLURM_CONF_PARAMETERS, PEER_RELATION, SLURM_CONF_PATH
from custom_exceptions import IngressAddressUnavailableError
from interface_slurmd import (
PartitionAvailableEvent,
PartitionUnavailableEvent,
Expand Down Expand Up @@ -307,7 +308,7 @@ def _assemble_slurmctld_parameters() -> str:

slurm_conf = {
"ClusterName": self.cluster_name,
"SlurmctldAddr": self._slurmd_ingress_address,
"SlurmctldAddr": self._ingress_address,
"SlurmctldHost": self.hostname,
"SlurmctldParameters": _assemble_slurmctld_parameters(),
"ProctrackType": "proctrack/linuxproc" if is_container() else "proctrack/cgroup",
Expand Down Expand Up @@ -403,12 +404,15 @@ def hostname(self) -> str:
return self._slurmctld_manager.hostname

@property
def _slurmd_ingress_address(self) -> str:
"""Return the ingress_address from the slurmd relation if it exists."""
ingress_address = ""
if binding := self.model.get_binding("slurmd"):
ingress_address = f"{binding.network.ingress_address}"
return ingress_address
def _ingress_address(self) -> str:
"""Return the ingress_address from the peer relation if it exists."""
if (peer_binding := self.model.get_binding(PEER_RELATION)) is not None:
logger.debug(
"Getting ingress_address: %s",
peer_binding.network.ingress_address,
)
return str(peer_binding.network.ingress_address)
raise IngressAddressUnavailableError

@property
def slurm_installed(self) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions charms/slurmctld/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""This module provides constants for the slurmctld-operator charm."""
from pathlib import Path

PEER_RELATION = "slurmctld-peer"

SLURM_CONF_PATH = Path("/etc/slurm/slurm.conf")
SLURM_USER = "slurm"
SLURM_GROUP = "slurm"
Expand Down

0 comments on commit 240498a

Please sign in to comment.