This is the multi-page printable view of this section. Click here to print.
Dev
- 1: Architecture
- 2: Cluster Control
- 3: Develop
- 4: NodeSet Controller
1 - Architecture
Overview
This document describes the high-level architecture of the Slinky
slurm-operator
.
Big Picture
The slurm-operator
follows the Kubernetes
operator pattern.
Operators are software extensions to Kubernetes that make use of custom resources to manage applications and their components. Operators follow Kubernetes principles, notably the control loop.
The slurm-operator
has one controller for each Custom Resource Definition
(CRD) that it is responsible to manage. Each controller has a control loop where
the state of the Custom Resource (CR) is reconciled.
Often, an operator is only concerned about data reported by the Kubernetes API.
In our case, we are also concerned about data reported by the Slurm API, which
influences how the slurm-operator
reconciles certain CRs.
Directory Map
This project follows the conventions of:
api/
Contains Custom Kubernetes API definitions. These become Custom Resource Definitions (CRDs) and are installed into a Kubernetes cluster.
cmd/
Contains code to be compiled into binary commands.
config/
Contains yaml configuration files used for kustomize deployments.
docs/
Contains project documentation.
hack/
Contains files for development and Kubebuilder. This includes a kind.sh script that can be used to create a kind cluster with all pre-requisites for local testing.
helm/
Contains helm deployments, including the configuration files such as values.yaml.
Helm is the recommended method to install this project into your Kubernetes cluster.
internal/
Contains code that is used internally. This code is not externally importable.
internal/controller/
Contains the controllers.
Each controller is named after the Custom Resource Definition (CRD) it manages. Currently, this consists of the nodeset and the cluster CRDs.
2 - Cluster Control
Overview
This controller is responsible for managing and reconciling the Cluster CRD. A
CRD represents communication to a Slurm cluster via slurmrestd and auth/jwt
.
This controller uses the Slurm client library.
Sequence Diagram
sequenceDiagram autonumber actor User as User participant KAPI as Kubernetes API participant CC as Cluster Controller box Operator Internals participant SCM as Slurm Client Map participant SEC as Slurm Event Channel end %% Operator Internals note over KAPI: Handle CR Creation User->>KAPI: Create Cluster CR KAPI-->>CC: Watch Cluster CRD CC->>+KAPI: Get referenced secret KAPI-->>-CC: Return secret create participant SC as Slurm Client CC->>+SC: Create Slurm Client for Cluster SC-->>-CC: Return Slurm Client Status loop Watch Slurm Nodes SC->>+SAPI: Get Slurm Nodes SAPI-->>-SC: Return Slurm Nodes SC->>SEC: Add Event for Cache Delta end %% loop Watch Slurm Nodes CC->>SCM: Add Slurm Client to Map CC->>+SC: Ping Slurm Control Plane SC->>+SAPI: Ping Slurm Control Plane SAPI-->>-SC: Return Ping SC-->>-CC: Return Ping CC->>KAPI: Update Cluster CR Status note over KAPI: Handle CR Deletion User->>KAPI: Delete Cluster CR KAPI-->>CC: Watch Cluster CRD SCM-->>CC: Lookup Slurm Client destroy SC CC-)SC: Shutdown Slurm Client CC->>SCM: Remove Slurm Client from Map participant SAPI as Slurm REST API
3 - Develop
This document aims to provide enough information that you can get started with development on this project.
Getting Started
You will need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against your choice of remote cluster.
Note: Your controller will automatically use the current context in your
kubeconfig file (i.e. whatever cluster kubectl cluster-info
shows).
Dependencies
Install KIND and Golang binaries for pre-commit hooks.
sudo apt-get install golang
make install
Pre-Commit
Install pre-commit and install the git hooks.
sudo apt-get install pre-commit
pre-commit install
Docker
Install Docker and configure rootless Docker.
After, test that your user account and communicate with docker.
docker run hello-world
Helm
Install Helm.
sudo snap install helm --classic
Skaffold
Install Skaffold.
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/
If google-cloud-sdk is installed, skaffold is available as an additional component.
sudo apt-get install -y google-cloud-cli-skaffold
Kubernetes Client
Install kubectl.
sudo snap install kubectl --classic
If google-cloud-sdk is installed, kubectl is available as an additional component.
sudo apt-get install -y kubectl
Running on the Cluster
For development, all Helm deployments use a values-dev.yaml
. If they do not
exist in your environment yet or you are unsure, safely copy the values.yaml
as a base by running:
make values-dev
Automatic
You can use Skaffold to build and push images, and deploy components using:
cd helm/slurm-operator/
skaffold run
NOTE: The skaffold.yaml
is configured to inject the image and tag into the
values-dev.yaml
so they are correctly referenced.
Operator
The slurm operator aims to follow the Kubernetes Operator pattern.
It uses Controllers, which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
Install CRDs
When deploying a helm chart with skaffold or helm, the CRDs defined in its
crds/
directory will be installed if not already present in the cluster.
Uninstall CRDs
To delete the Operator CRDs from the cluster:
make uninstall
WARNING: CRDs do not upgrade! The old ones must be uninstalled first so the new ones can be installed. This should only be done in development.
Modifying the API Definitions
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
make manifests
Slurm Version Changed
If the Slurm version has changed, generate the new OpenAPI spec and its golang client code using:
make generate
NOTE: Update code interacting with the API in accordance with the slurmrestd plugin lifecycle.
Running the operator locally
Install the operator’s CRDs with make install
.
Launch the operator via the VSCode debugger using the “Launch Operator” launch task.
Because the operator will be running outside of Kubernetes and needs to
communicate to the Slurm cluster, set the following options in you Slurm helm
chart’s values.yaml
:
debug.enable=true
debug.localOperator=true
If running on a Kind cluster, also set:
debug.disableCgroups=true
If the Slurm helm chart is being deployed with skaffold, run
skaffold run --port-forward --tail
. It is configured to automatically
port-forward the restapi for the local operator to
communicate with the Slurm cluster.
If skaffold is not used, manually run
kubectl port-forward --namespace slurm services/slurm-restapi 6820:6820
for
the local operator to communicate with the Slurm cluster.
After starting the operator, verify it is able to contact the Slurm cluster by checking that the Cluster CR has been marked ready:
$ kubectl get --namespace slurm clusters.slinky.slurm.net
NAME READY AGE
slurm true 110s
See skaffold port-forwarding to learn how skaffold automatically detects which services to forward.
4 - NodeSet Controller
Overview
The nodeset controller is responsible for managing and reconciling the NodeSet CRD, which represents a set of homogeneous Slurm Nodes.
Design
This controller is responsible for managing and reconciling the NodeSet CRD. In addition to the regular responsibility of managing resources in Kubernetes via the Kubernetes API, this controller should take into consideration the state of Slurm to make certain reconciliation decisions.
Sequence Diagram
sequenceDiagram autonumber actor User as User participant KAPI as Kubernetes API participant NS as NodeSet Controller box Operator Internals participant SCM as Slurm Client Map participant SEC as Slurm Event Channel end %% Operator Internals participant SC as Slurm Client participant SAPI as Slurm REST API loop Watch Slurm Nodes SC->>+SAPI: Get Slurm Nodes SAPI-->>-SC: Return Slurm Nodes SC->>SEC: Add Event for Cache Delta end %% loop Watch Slurm Nodes note over KAPI: Handle CR Update SEC-->>NS: Watch Event Channel User->>KAPI: Update NodeSet CR KAPI-->>NS: Watch NodeSet CRD opt Scale-out Replicas NS->>KAPI: Create Pods end %% Scale-out Replicas opt Scale-in Replicas SCM-->>NS: Lookup Slurm Client NS->>+SC: Drain Slurm Node SC->>+SAPI: Drain Slurm Node SAPI-->>-SC: Return Drain Slurm Node Status SC-->>-NS: Drain Slurm Node alt Slurm Node is Drained NS->>KAPI: Delete Pod else NS->>NS: Check Again Later end %% alt Slurm Node is Drained end %% opt Scale-in Replicas