diff --git a/.gitignore b/.gitignore index d91fc203..380d29dd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ ext/ env/ .kubespray/ +.cpu-pinning-operator/ *.log # Helm subchart packages — rebuilt from Chart.lock by dependency_update diff --git a/configs/components.yaml b/configs/components.yaml index 3b170cf9..24f4ba4c 100644 --- a/configs/components.yaml +++ b/configs/components.yaml @@ -231,6 +231,17 @@ components: # keycloak: Grafana sign-in (observability_grafana_sso). depends_on: [cert_manager, metallb, seaweedfs, keycloak] + # kubernetes_cpu_policy: cpu-pinning-operator, the alternative to nri_cpu_balloons + # (its chart bundles the same balloons plugin). Platform, like nri_cpu_balloons: its + # webhook pins model pods, so `teardown inference` keeps it. After observability so + # the chart finds the ServiceMonitor CRD. teardown: role, for helm uninstall's hooks. + # On any kubernetes_accelerator: it pins GPU pods too (balloon-device). + - name: cpu_pinning_operator + layer: platform + teardown: role + enabled: "{{ (kubernetes_cpu_policy | default('nri-balloons')) == 'cpu-pinning-operator' }}" + depends_on: [cert_manager, observability] + # Event-driven autoscaling (external.metrics.k8s.io); triggers query the platform # Prometheus. On OpenShift it uses the Custom Metrics Autoscaler, which preflight checks. - name: keda diff --git a/configs/defaults/global_config.yaml b/configs/defaults/global_config.yaml index e699b796..0d5a10b7 100644 --- a/configs/defaults/global_config.yaml +++ b/configs/defaults/global_config.yaml @@ -99,7 +99,7 @@ seaweedfs_volume_storage_size: "10Gi" node_topology_enabled: true # platform pods on control-plane nodes, inference on workers (soft) enforce_pss: true # Pod Security labels on every namespace the installer creates -kubernetes_cpu_policy: "nri-balloons" # keep: model-manager and inference need NRI CPU pinning +kubernetes_cpu_policy: "nri-balloons" # or cpu-pinning-operator (docs/configuration/cpu-pinning-operator.md), kubelet-static, best-effort kubernetes_accelerator: "cpu" # cpu: the kubelet CPU/NUMA tuning for Xeon rack_scale_enabled: false # rack-scale fabric; needs env//rack-profile.yaml envoy_gateway_upgrade: true # Envoy Gateway 1.9.3 with ListenerSets; false: 1.7.5. Never downgrades diff --git a/docs/README.md b/docs/README.md index 28f96650..450601b6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,7 @@ Start with the table. Each row is one job and one page. The sections under it ar | Use the Kubernetes cluster dashboard and platform sign-in | [Kubernetes cluster dashboard (Headlamp)](configuration/headlamp.md) | | Open Grafana and read the dashboards | [Observability](configuration/observability.md) | | Place platform and inference pods on different nodes | [Node topology](configuration/node-topology.md) | -| Pin inference pods to CPU cores | [NRI CPU balloons](configuration/nri-cpu-balloons.md) | +| Pin inference pods to CPU cores | [NRI CPU balloons](configuration/nri-cpu-balloons.md) or [CPU Pinning Operator](configuration/cpu-pinning-operator.md) | | Connect my application or framework | [Integration guide](reference/integration.md) | | Look up a command or flag | [CLI reference](reference/cli.md) | | See how a request reaches a model | [Network architecture](reference/networking.md) | @@ -84,6 +84,7 @@ Edit the YAML under `env//` and re-run `install`. | [Observability](configuration/observability.md) | Opening Grafana and signing in: local admin or Keycloak, roles, and the validate checks | | [Node topology](configuration/node-topology.md) | Separating platform and inference workloads on multi-node clusters | | [NRI CPU balloons](configuration/nri-cpu-balloons.md) | NUMA-aware CPU pinning for inference pods | +| [CPU Pinning Operator](configuration/cpu-pinning-operator.md) | The same pinning, run by an operator that pins model pods at admission | ## Connect an application diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 349e1693..8101a3e9 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -180,7 +180,7 @@ is left as it is (or commented out). | `node_topology_enabled` | Prefer control-plane nodes for platform pods and worker nodes for models (a preference, not a rule). Default `true` — see [Node Topology](node-topology.md) | | `enforce_pss` | Pod Security labels on every namespace the installer creates. Default `true` — see [Namespace Security Labels](../reference/labels.md) | | `kubernetes_cpu_policy` | CPU pinning strategy for inference workloads. Default `nri-balloons` — see [CPU policy](#cpu-policy) | -| `kubernetes_accelerator` | Compute target for inference workloads. Default `cpu` (Intel® Xeon®: tune the kubelet's CPU/NUMA settings); CPU pinning is turned off for any other value | +| `kubernetes_accelerator` | Compute target for inference workloads. Default `cpu` (Intel® Xeon®: tune the kubelet's CPU/NUMA settings); CPU pinning is turned off for any other value, unless `kubernetes_cpu_policy: cpu-pinning-operator` | | `rack_scale_enabled` | Rack-scale fabric; needs `env//rack-profile.yaml`. Default `false` — see [Rack-scale deployment](../deployment/rack-scale.md) | | `envoy_gateway_upgrade` | `true` (default): install Envoy Gateway 1.9.3 instead of 1.7.5 (and upgrade an older one in place); the inference layer then installs KServe 0.21. `false`: 1.7.5. Never downgrades | | `rook_ceph_devices`, `rook_ceph_teardown_wipe_devices` | `storage_backend: ceph` only — see [Storage](#storage) | @@ -358,11 +358,12 @@ from it. | Value | What it does | When to use | |---|---|---| | `nri-balloons` (default) | Installs the NRI balloons plugin: NUMA-aware pinning with hyperthread isolation. Pods keep normal (Burstable) QoS | Recommended — best performance on multi-socket Xeon nodes | +| `cpu-pinning-operator` | Installs the [CPU Pinning Operator](cpu-pinning-operator.md): the same NRI balloons plugin, with an admission webhook that pins model pods and a Grafana per-core map | Pinning kept in step with the nodes by an operator, with dashboards | | `kubelet-static` | Configures the kubelet's static CPU manager (`full-pcpus-only`). Pods become Guaranteed QoS. No NRI plugin | Clusters that cannot run NRI | | `best-effort` | No pinning: the scheduler places threads | Development, or small clusters | -Any other value stops preflight. Pinning only applies with `kubernetes_accelerator: cpu`. See -[NRI CPU Balloons](nri-cpu-balloons.md) for per-node balloon sizing. +Any other value stops preflight. Pinning only applies with `kubernetes_accelerator: cpu`, except `cpu-pinning-operator`, which pins GPU pods too. See +[NRI CPU Balloons](nri-cpu-balloons.md) for per-node balloon sizing, or [CPU Pinning Operator](cpu-pinning-operator.md). --- diff --git a/docs/configuration/cpu-pinning-operator.md b/docs/configuration/cpu-pinning-operator.md new file mode 100644 index 00000000..0c6ac00b --- /dev/null +++ b/docs/configuration/cpu-pinning-operator.md @@ -0,0 +1,97 @@ +# CPU Pinning Operator + +[← Docs index](../README.md) + +`kubernetes_cpu_policy: cpu-pinning-operator` pins model servers to their own NUMA-local cores with the [CPU Pinning Operator](https://github.com/intel/cpu-pinning-operator) instead of the `nri_cpu_balloons` role. Both run the same NRI balloons plugin. The difference is who decides the pinning: + +| | `nri-balloons` | `cpu-pinning-operator` | +|---|---|---| +| Per-node `BalloonsPolicy` | written by the installer at install and `add-node` | written by the operator, kept in step with every node it sees | +| Model pod annotation | added by `model-manager` | added by the operator's admission webhook | +| Plugin namespace | `kube-system` | `cpu-pinning-operator-system` | +| GPU model pods | not pinned | pinned to dedicated cores (`balloon-device`) | +| Dashboards | — | Grafana per-core map per node, plus a cluster overview | + +Unlike the other policies, this one also applies when `kubernetes_accelerator` is not `cpu`. + +## Enable it + +In `env//global_config.yaml`, before `install platform`: + +```yaml +kubernetes_cpu_policy: "cpu-pinning-operator" +``` + +`install platform` (or any layer above) then installs the chart from a checkout of the operator's release tag (`cpu_pinning_operator_version`, default `v1.0.0`) into `.cpu-pinning-operator/`. The kubelet stays on `cpuManagerPolicy: none`, as with `nri-balloons`. To install or re-apply the operator on its own: + +```bash +./toolkit_manager.sh install cpu_pinning_operator --env +./toolkit_manager.sh validate cpu_pinning_operator --env +``` + +**Switching from `nri-balloons`:** undeploy the models and run `./toolkit_manager.sh teardown nri_cpu_balloons` while the policy is still `nri-balloons`. Then change the policy, install, and deploy the models again. The install stops while the `nri_cpu_balloons` plugin still runs, because two balloons plugins on one node fight over the same cores. To switch back, do the reverse with `teardown cpu_pinning_operator`. + +## What gets pinned + +The operator pins model-manager's serving containers in `llm-inference`: `main` (vLLM, `LLMInferenceService`) and `kserve-container` (OVMS, `InferenceService`). It reads the number of NUMA nodes from `--tensor-parallel-size`, or from the pod annotation `cpu-pinning-operator.intel.com/tp`. `model-manager deploy` needs no change. Check a model: + +```bash +POD=$(kubectl -n llm-inference get pod -l app.kubernetes.io/name=qwen3-0-6b -o name | head -1) +kubectl -n llm-inference get $POD -o jsonpath='{.metadata.annotations}' | tr , '\n' | grep balloon +kubectl -n llm-inference exec $POD -c main -- grep Cpus_allowed_list /proc/self/status +``` + +**GPU models** (`vllm-cuda`, `vllm-xpu`) are pinned too. model-manager gives the pod a CPU limit equal to its request, in whole cores, and the operator puts any pod that requests a device (`nvidia.com/gpu`, `gpu.intel.com/xe`) in its `balloon-device` type. Those cores are dedicated, but they are not steered to the GPU's NUMA node. That needs the kubelet's alpha `KubeletPodResourcesGet` feature gate, which the installer does not turn on (upstream advises against it). + +## Reserved CPUs + +Every pod that is not pinned runs on the reserved pool. It is sized by the same settings as `nri-balloons` ([Reserved CPU sizing](nri-cpu-balloons.md#3-reserved-cpu-sizing)), so switching policy keeps the split: + +| Setting | Operator gets | +|---|---| +| `nri_deployment_profile: siblings` (default) | physical cores for models; every hyperthread sibling reserved | +| `minimal` / `standard` / `observability` / `full` | 8 / 12 / 16 / 20 CPUs reserved; models may get hyperthreads | +| `nri_reserved_cpu_list: "0-3,64-67"` | that many CPUs reserved (8). The operator picks the CPU IDs. | + +The operator keeps each node's reservation between 4 CPUs and 25% of its physical cores. + +## Settings + +| Variable | Default | | +|---|---|---| +| `cpu_pinning_operator_version` | `v1.0.0` | Release tag of the chart and image | +| `cpu_pinning_operator_containers` | `["main", "kserve-container"]` | Container names to pin (globs allowed) | +| `cpu_pinning_operator_namespaces` | `["llm-inference"]` | Namespaces the webhook watches | +| `cpu_pinning_operator_pct_enabled` | `true` | Intel® Priority Core Turbo, see below | +| `cpu_pinning_operator_extra_values` | `{}` | Any other [chart value](https://github.com/intel/cpu-pinning-operator/blob/main/deploy/cpu-pinning-operator/values.yaml), merged last | + +For example, to refuse a model pod that does not fit instead of only warning about it: + +```yaml +cpu_pinning_operator_extra_values: + balloonPinningPolicy: + capacityCheck: + mode: enforce +``` + +## Intel® Priority Core Turbo + +On by default. The operator gives every policy two CPU classes, applied through Intel® Speed Select Technology – Core Power (SST-CP): + +- `gpu-hp` (high priority) for GPU pods' cores (`balloon-device`) +- `cpu-lp` (low priority) for CPU model balloons + +The reserved pool gets no class. PCT takes effect only on Xeon® processors that support it, with SST enabled in the BIOS and the kernel's `isst_if` driver providing `/dev/isst_interface`. Elsewhere the plugin logs `pct: SST not supported on this host; ignoring PCT fields in cpuClasses` and pins as usual. + +To apply the classes, the balloons plugin runs **privileged** with the host's `/dev` mounted (the `allowPCT` chart value). On OpenShift it then gets the `privileged` SCC. Turn it off with `cpu_pinning_operator_pct_enabled: false`, which returns the plugin to a hostPath-only, unprivileged pod. + +On a node with SST, CPU model balloons are low priority, so on a CPU-only inference node they can run at a lower turbo frequency than platform pods. Measure tokens per second with PCT on and off before relying on it for CPU inference. + +## Limitations + +- `model-manager` runs no placement pre-flight under this policy, so the operator's capacity check (`warn` by default) is the only one. A model-manager older than this policy logs `Invalid MM_CPU_POLICY='cpu-pinning-operator'` and deploys as `best-effort`; the webhook still pins the pod. +- A pod created before a node is provisioned is admitted unpinned or denied (`enforcePinning`), so the install waits until `BalloonsClusterConfig/cluster` is `Ready`. +- `nri_reserved_cpu_list` keeps only its size: the operator chooses which CPUs. +- Helm does not upgrade CRDs. If a new operator release changes its CRDs, apply them from the new checkout first. + +Troubleshooting, architecture and every chart value: the operator's [documentation](https://github.com/intel/cpu-pinning-operator/tree/main/docs). diff --git a/docs/configuration/nri-cpu-balloons.md b/docs/configuration/nri-cpu-balloons.md index 3618da5f..97c7e2c1 100644 --- a/docs/configuration/nri-cpu-balloons.md +++ b/docs/configuration/nri-cpu-balloons.md @@ -12,7 +12,7 @@ Two terms used throughout: - **Balloon**: a named set of CPU cores. A container placed in a balloon runs only on those cores. > [!NOTE] -> `kubernetes_cpu_policy: nri-balloons` is the default on CPU clusters (`kubernetes_accelerator: cpu`). With `kubelet-static` or `best-effort`, or on a GPU cluster, the components below are not deployed and models are scheduled without balloon pinning. +> `kubernetes_cpu_policy: nri-balloons` is the default on CPU clusters (`kubernetes_accelerator: cpu`). With `cpu-pinning-operator` ([its own guide](cpu-pinning-operator.md)), `kubelet-static` or `best-effort`, or on a GPU cluster, the components below are not deployed and models are scheduled without balloon pinning. --- diff --git a/docs/reference/architecture.md b/docs/reference/architecture.md index 975b3420..82d7fe72 100644 --- a/docs/reference/architecture.md +++ b/docs/reference/architecture.md @@ -35,7 +35,7 @@ infrastructure → platform → inference → erag / agent-toolkit (opt-in | Layer | Components (in [configs/components.yaml](../../configs/components.yaml) unless noted) | Installed by | |---|---|---| | `infrastructure` | `kubernetes`, `storage`; `kata_containers` (`kata_containers_enabled`); rack-scale only (`rack_scale_enabled`): `fabric_inventory`, `fabric_netplan`, `fabric_sysctl`, `fabric_bgp`, `fabric_validate` | `install` of any layer | -| `platform` | `node_feature_discovery`, `nri_cpu_balloons`, `intel_gpu_plugin`, `cert_manager`, `istio`, `metallb`, `metrics_server`, `gateway` (alias `envoy_gateway`), `postgresql`, `keycloak`, `object_store`, `seaweedfs`, `observability`, `headlamp`; opt-in: `keda`, `velero`; rack-scale: `nvidia_gpu_operator`, `gpu_observability` | `install` of `platform` or any layer above | +| `platform` | `node_feature_discovery`, `nri_cpu_balloons` or `cpu_pinning_operator`, `intel_gpu_plugin`, `cert_manager`, `istio`, `metallb`, `metrics_server`, `gateway` (alias `envoy_gateway`), `postgresql`, `keycloak`, `object_store`, `seaweedfs`, `observability`, `headlamp`; opt-in: `keda`, `velero`; rack-scale: `nvidia_gpu_operator`, `gpu_observability` | `install` of `platform` or any layer above | | `inference` | from inference-toolkit's `components.yaml`: `keycloak_config`, `envoy_ai_gateway`, `kserve`, `litellm`, `langfuse`, `llm_services`, `vllm_sr` (opt-in) | `install inference`, or a layer above it | | `erag` | from enterprise-rag's `components.yaml` (the `app_*` roles) | `install erag`, after `init erag` | | `agent-toolkit` | from enterprise-agent-toolkit's `components.yaml` | `install agent-toolkit`, after `init agent-toolkit` | @@ -432,6 +432,7 @@ All roles follow the same pattern: `defaults/main.yaml` for config, `tasks/main. | `velero` | Cluster backups (opt-in, `velero_enabled`; needs snapshot-capable storage). | | `nvidia_gpu_operator`, `gpu_observability` | NVIDIA GPU nodes on rack-scale: the GPU Operator, DCGM metrics and dashboards. | | `nri_cpu_balloons` | NRI CPU-balloons plugin. Generates per-node `BalloonsPolicy` CRs based on NUMA topology. Enabled only when `kubernetes_cpu_policy=nri-balloons` and `kubernetes_accelerator=cpu` ([NRI CPU Balloons](../configuration/nri-cpu-balloons.md)). | +| `cpu_pinning_operator` | [CPU Pinning Operator](https://github.com/intel/cpu-pinning-operator): the same balloons plugin, with per-node policies and an admission webhook that pins matched model pods. Enabled only when `kubernetes_cpu_policy=cpu-pinning-operator`, on any `kubernetes_accelerator`: it pins GPU pods too ([CPU Pinning Operator](../configuration/cpu-pinning-operator.md)). | | `ownership` | Library role: labels what each component creates and deletes it on teardown. | | `layer_checks` | Library role: deployment records, run classes and the checks before an install or teardown. | | `backup` | Library role used by `playbooks/backup.yaml`. | diff --git a/docs/reference/cli.md b/docs/reference/cli.md index d8378725..058a58b2 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -164,7 +164,7 @@ refuses a blocking verdict. See [Upgrade a Layer](../deployment/upgrade.md). | Target | What it covers | |---|---| | `infrastructure` | `kubernetes`, `storage`; plus `kata_containers` (`kata_containers_enabled`) and the `fabric_*` rack-scale networking components (`rack_scale_enabled`) when switched on | -| `platform` | `cert_manager`, `istio`, `metallb`, `gateway` (also accepted as `envoy_gateway`), `postgresql`, `keycloak`, `object_store`, `seaweedfs`, `observability`, `metrics_server`, `node_feature_discovery`, `nri_cpu_balloons`, `intel_gpu_plugin` (Intel GPU nodes only); plus `headlamp`, `keda` and `velero` when switched on, and `nvidia_gpu_operator` / `gpu_observability` on rack-scale | +| `platform` | `cert_manager`, `istio`, `metallb`, `gateway` (also accepted as `envoy_gateway`), `postgresql`, `keycloak`, `object_store`, `seaweedfs`, `observability`, `metrics_server`, `node_feature_discovery`, `nri_cpu_balloons` (or `cpu_pinning_operator`, by `kubernetes_cpu_policy`), `intel_gpu_plugin` (Intel GPU nodes only); plus `headlamp`, `keda` and `velero` when switched on, and `nvidia_gpu_operator` / `gpu_observability` on rack-scale | | `inference` | `keycloak_config`, `envoy_ai_gateway`, `kserve`, `llm_services`; plus `litellm` and `langfuse` (with `auth_type: litellm_vkey` or `litellm_enabled: true`), and `vllm_sr` when switched on. Comes from the inference repository | | `erag` | The Intel® Chatbot Toolkit components (vector databases, document ingestion, chat UI, …). Comes from its repository; opt-in | | `agent-toolkit` | The Intel® Agent Toolkit components (agent sandboxes, memory stores, …). Comes from its repository; opt-in | diff --git a/docs/reference/labels.md b/docs/reference/labels.md index a75890e0..2e4cd168 100644 --- a/docs/reference/labels.md +++ b/docs/reference/labels.md @@ -54,6 +54,7 @@ Includes the infrastructure-layer storage namespaces (`csi-driver-nfs`, `rook-ce | `intel-gpu-plugin` | `privileged` | `privileged` | `privileged` | — | `intel_gpu_plugin` | `intel_gpu_plugin_enabled: true` and a node has an Intel GPU | | `headlamp` | `restricted` | `restricted` | `restricted` | `ambient` | `headlamp` | `headlamp_enabled: true` | | `keda` | `restricted` | `restricted` | `restricted` | `ambient` | `keda` | `keda_enabled: true` | +| `cpu-pinning-operator-system` | `privileged` | `privileged` | `privileged` | — | `cpu_pinning_operator` | `kubernetes_cpu_policy: cpu-pinning-operator` | | `velero` | `baseline` | `baseline` | `baseline` | `ambient` | `velero` | `velero_enabled: true` | | `csi-driver-nfs` | `privileged` | `privileged` | `privileged` | — | `nfs_storage` | `storage_backend: nfs` | | `rook-ceph` | `privileged` | `privileged` | `privileged` | — | `rook_ceph_storage` | `storage_backend: ceph` | diff --git a/playbooks/includes/preflight.yaml b/playbooks/includes/preflight.yaml index ae37a801..5829414a 100644 --- a/playbooks/includes/preflight.yaml +++ b/playbooks/includes/preflight.yaml @@ -279,11 +279,14 @@ # cpuManagerPolicy=none, kubelet-static needs it =static). # # nri-balloons (default) NRI balloons resource policy — NUMA-aware pinning +# cpu-pinning-operator the same plugin, run by intel/cpu-pinning-operator; +# its webhook pins the model pods it matches # kubelet-static kubelet static CPU manager — Guaranteed-QoS exclusive CPUs # best-effort no pinning, standard CFS scheduler # # The derived facts are consumed by: -# - configs/components.yaml → gates the nri_cpu_balloons role +# - configs/components.yaml → gates the nri_cpu_balloons and +# cpu_pinning_operator roles # - roles/kubernetes → kubespray_extra_auto.yml (kubelet flags, # reservedSystemCPUs) + reserved-CPU calc # - the inference stack → MM_CPU_POLICY for model-manager @@ -291,18 +294,19 @@ - name: "Preflight - CPU policy: validate value" ansible.builtin.assert: that: - - kubernetes_cpu_policy | default('nri-balloons') in ['nri-balloons', 'kubelet-static', 'best-effort'] + - kubernetes_cpu_policy | default('nri-balloons') in ['nri-balloons', 'cpu-pinning-operator', 'kubelet-static', 'best-effort'] fail_msg: >- Invalid kubernetes_cpu_policy='{{ kubernetes_cpu_policy | default('') }}'. - Must be one of: nri-balloons (default), kubelet-static, best-effort. + Must be one of: nri-balloons (default), cpu-pinning-operator, kubelet-static, best-effort. quiet: true -# GPU clusters do no CPU pinning at all — the device plugin and GPU scheduler -# own placement. Downgrade to best-effort rather than half-configuring kubelet. +# GPU clusters do no CPU pinning — the device plugin and GPU scheduler own +# placement — except cpu-pinning-operator, which pins GPU pods too. Downgrade to +# best-effort rather than half-configuring kubelet. - name: "Preflight - CPU policy: force best-effort on non-CPU accelerators" when: - (kubernetes_accelerator | default('cpu')) != 'cpu' - - (kubernetes_cpu_policy | default('nri-balloons')) != 'best-effort' + - (kubernetes_cpu_policy | default('nri-balloons')) not in ['best-effort', 'cpu-pinning-operator'] block: - name: "Preflight - CPU policy: warn that accelerator overrides pinning" ansible.builtin.debug: @@ -315,13 +319,14 @@ ansible.builtin.set_fact: kubernetes_cpu_policy: "best-effort" -- name: "Preflight - CPU policy: derive settings for nri-balloons" +# cpu-pinning-operator runs the same balloons plugin, which needs cpuManagerPolicy=none. +- name: "Preflight - CPU policy: derive settings for nri-balloons / cpu-pinning-operator" ansible.builtin.set_fact: - nri_cpu_balloons_enabled: true + nri_cpu_balloons_enabled: "{{ (kubernetes_cpu_policy | default('nri-balloons')) == 'nri-balloons' }}" kubelet_cpu_manager_policy: "none" kubelet_topology_manager_policy: "none" kubelet_cpu_manager_policy_options: {} - when: (kubernetes_cpu_policy | default('nri-balloons')) == 'nri-balloons' + when: (kubernetes_cpu_policy | default('nri-balloons')) in ['nri-balloons', 'cpu-pinning-operator'] # kubelet-static: NRI must stay off (its balloon cpusets would fight the # kubelet CPU manager for the same cores). The kubelet_* values fall back to the diff --git a/roles/cpu_pinning_operator/defaults/main.yaml b/roles/cpu_pinning_operator/defaults/main.yaml new file mode 100644 index 00000000..2b2f115c --- /dev/null +++ b/roles/cpu_pinning_operator/defaults/main.yaml @@ -0,0 +1,41 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# ============================================================================= +# CPU Pinning Operator (https://github.com/intel/cpu-pinning-operator) +# ============================================================================= +# Selected with kubernetes_cpu_policy: cpu-pinning-operator. The operator probes +# each node's NUMA topology, writes the per-node BalloonsPolicy CRs and, through +# an admission webhook, annotates the model pods it matches, so model-manager +# deploys them without any balloon annotation of its own. The chart bundles the +# NRI balloons plugin, so it replaces the nri_cpu_balloons role, never runs next to it. + +# No chart repository is published: the chart is installed from a checkout of this tag. +cpu_pinning_operator_repo: "https://github.com/intel/cpu-pinning-operator" +cpu_pinning_operator_version: "v1.0.0" +cpu_pinning_operator_src_dir: "{{ playbook_dir }}/../.cpu-pinning-operator" + +cpu_pinning_operator_namespace: "cpu-pinning-operator-system" +cpu_pinning_operator_release: "cpu-pinning-operator" + +# What to pin: model-manager's serving containers. `main` is the vLLM container of an +# LLMInferenceService, `kserve-container` the OVMS predictor of an InferenceService. +# The span (NUMA nodes) is read off --tensor-parallel-size, as nri-balloons does. +cpu_pinning_operator_containers: ["main", "kserve-container"] +cpu_pinning_operator_namespaces: ["llm-inference"] + +# The reserved pool: the same settings, and defaults, as nri_cpu_balloons +# (docs/configuration/nri-cpu-balloons.md#3-reserved-cpu-sizing). +# siblings (default) hyperthread siblings reserved, models get physical cores +# minimal | standard | observability | full 8 | 12 | 16 | 20 CPUs reserved +# nri_reserved_cpu_list (a cpuset) wins; the operator reserves that many CPUs. +nri_deployment_profile: "siblings" +nri_reserved_cpu_list: "" + +# Intel® Priority Core Turbo: the plugin applies the operator's CPU classes (GPU pods' +# cores high priority, CPU model balloons low) through SST-CP. Runs the plugin +# privileged with the host's /dev; a no-op on nodes without /dev/isst_interface. +cpu_pinning_operator_pct_enabled: true + +# Any other chart value (deploy/cpu-pinning-operator/values.yaml), merged last. +cpu_pinning_operator_extra_values: {} diff --git a/roles/cpu_pinning_operator/meta/main.yaml b/roles/cpu_pinning_operator/meta/main.yaml new file mode 100644 index 00000000..58ed593a --- /dev/null +++ b/roles/cpu_pinning_operator/meta/main.yaml @@ -0,0 +1,4 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +dependencies: [] diff --git a/roles/cpu_pinning_operator/tasks/install.yaml b/roles/cpu_pinning_operator/tasks/install.yaml new file mode 100644 index 00000000..376afa95 --- /dev/null +++ b/roles/cpu_pinning_operator/tasks/install.yaml @@ -0,0 +1,129 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# ============================================================================= +# CPU Pinning Operator — Install (chart from a checkout of the release tag) +# ============================================================================= + +# Two balloons plugins on one node fight over the same cpusets. +- name: "cpu_pinning_operator | Look for the nri_cpu_balloons plugin" + kubernetes.core.k8s_info: + api_version: apps/v1 + kind: DaemonSet + name: nri-resource-policy-balloons + namespace: kube-system + register: _cpo_nri_ds + +- name: "cpu_pinning_operator | Assert nri_cpu_balloons is not installed" + ansible.builtin.assert: + that: _cpo_nri_ds.resources | length == 0 + fail_msg: >- + The nri_cpu_balloons plugin still runs in kube-system. Undeploy the models, set + kubernetes_cpu_policy back to nri-balloons and run + `./toolkit_manager.sh teardown nri_cpu_balloons`, then set it to cpu-pinning-operator again. + quiet: true + +# Not in the mesh: the API server calls the webhook directly. Privileged: the +# bundled balloons plugin mounts hostPath. +- name: "cpu_pinning_operator | Namespace" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ cpu_pinning_operator_namespace }}" + labels: >- + {{ {'pod-security.kubernetes.io/enforce': 'privileged', + 'pod-security.kubernetes.io/audit': 'privileged', + 'pod-security.kubernetes.io/warn': 'privileged'} + if enforce_pss | default(false) | bool else {} }} + +- name: "cpu_pinning_operator | Check out the chart at {{ cpu_pinning_operator_version }}" + ansible.builtin.git: + repo: "{{ cpu_pinning_operator_repo }}" + dest: "{{ cpu_pinning_operator_src_dir }}" + version: "{{ cpu_pinning_operator_version }}" + depth: 1 + force: true + register: _cpo_git + until: _cpo_git is succeeded + retries: "{{ helm_retries }}" + delay: 15 + +# The reserved pool as nri_deployment_profile / nri_reserved_cpu_list size it for +# nri-balloons (counts from nri_cpu_balloons' compute_reserved_cpus_advanced.sh). +# The operator takes a count, not CPU IDs, so a cpuset becomes its size. +- name: "cpu_pinning_operator | Reserved CPUs from nri_deployment_profile" + vars: + _cpo_profile: "{{ nri_deployment_profile }}" + _cpo_list: "{{ nri_reserved_cpu_list | trim }}" + _cpo_counts: {minimal: 8, standard: 12, observability: 16, full: 20} + _cpo_list_count: >- + {%- set ns = namespace(total=0) -%} + {%- for part in _cpo_list.split(',') if part -%} + {%- set ends = part.split('-') -%} + {%- set ns.total = ns.total + (ends[-1] | int) - (ends[0] | int) + 1 -%} + {%- endfor -%} + {{ ns.total }} + block: + - name: "cpu_pinning_operator | Assert a known profile" + ansible.builtin.assert: + that: _cpo_list or _cpo_profile in ['siblings'] + (_cpo_counts.keys() | list) + fail_msg: "nri_deployment_profile='{{ _cpo_profile }}': use siblings, minimal, standard, observability or full." + quiet: true + + - name: "cpu_pinning_operator | Balloon settings" + ansible.builtin.set_fact: + _cpo_balloon: >- + {{ {'cpuAllocation': 'physical-cores', 'htSiblingPolicy': 'reserved'} + if not _cpo_list and _cpo_profile == 'siblings' + else {'cpuAllocation': 'hyperthreads', + 'reserved': {'cpus': (_cpo_list_count | int) if _cpo_list else _cpo_counts[_cpo_profile]}} }} + +# ponytail: Helm installs crds/ but never upgrades them; a release that changes +# its CRDs needs them applied from the new checkout before the upgrade. +- name: "cpu_pinning_operator | Install via Helm" + vars: + _cpo_observability: "{{ observability_enabled | default(true) | bool }}" + kubernetes.core.helm: + name: "{{ cpu_pinning_operator_release }}" + chart_ref: "{{ cpu_pinning_operator_src_dir }}/deploy/cpu-pinning-operator" + release_namespace: "{{ cpu_pinning_operator_namespace }}" + create_namespace: false + wait: "{{ helm_wait }}" + timeout: "{{ helm_timeout }}" + values: >- + {{ {'affinity': _platform_affinity | default({}), + 'balloonPinningPolicy': {'match': {'byContainerName': cpu_pinning_operator_containers}, + 'namespaces': cpu_pinning_operator_namespaces}, + 'balloonsClusterConfig': {'balloon': _cpo_balloon}, + 'grafanaDashboard': {'enabled': _cpo_observability}, + 'nri-resource-policy-balloons': {'allowPCT': cpu_pinning_operator_pct_enabled | bool}, + 'metrics': {'readers': _cpu_pinning_operator_metrics_readers if _cpo_observability else []}} + | combine(_cpu_pinning_operator_platform_values, cpu_pinning_operator_extra_values, recursive=true) }} + register: _cpo_helm + until: _cpo_helm is succeeded + retries: "{{ helm_retries }}" + delay: 15 + +# Until then the webhook admits model pods unpinned (or denies them). +- name: "cpu_pinning_operator | Wait until a node is provisioned" + kubernetes.core.k8s_info: + api_version: cpu-pinning-operator.intel.com/v1alpha1 + kind: BalloonsClusterConfig + name: cluster + register: _cpo_bcc + until: >- + _cpo_bcc.resources | length > 0 + and (_cpo_bcc.resources[0].status.conditions | default([]) + | selectattr('type', 'eq', 'Ready') | selectattr('status', 'eq', 'True') | list | length > 0) + retries: 60 + delay: 10 + +- name: "cpu_pinning_operator | Install complete" + ansible.builtin.debug: + msg: >- + CPU Pinning Operator {{ cpu_pinning_operator_version }} in {{ cpu_pinning_operator_namespace }}: + pins containers {{ cpu_pinning_operator_containers | join(', ') }} in + {{ cpu_pinning_operator_namespaces | join(', ') }}. diff --git a/roles/cpu_pinning_operator/tasks/main.yaml b/roles/cpu_pinning_operator/tasks/main.yaml new file mode 100644 index 00000000..15fd2fdb --- /dev/null +++ b/roles/cpu_pinning_operator/tasks/main.yaml @@ -0,0 +1,20 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Canonical dispatcher (docs/reference/adding-solutions.md), the same in every +# role with platform values but for the name. +# vars/.yaml values that differ by platform; +# the tasks are the same on both +- name: "cpu_pinning_operator | dispatch | Assert supported action" + ansible.builtin.assert: + that: component_action | default('') in ['install', 'teardown', 'validate'] + fail_msg: "cpu_pinning_operator: unsupported component_action='{{ component_action | default('') }}'" + quiet: true + +- name: "cpu_pinning_operator | dispatch | Load {{ cluster_distribution }} values" + ansible.builtin.include_vars: "{{ role_path }}/vars/{{ cluster_distribution }}.yaml" + when: (role_path ~ '/vars/' ~ cluster_distribution ~ '.yaml') is file + +- name: "cpu_pinning_operator | dispatch | Include {{ component_action }}" + ansible.builtin.include_tasks: + file: "{{ component_action }}.yaml" diff --git a/roles/cpu_pinning_operator/tasks/teardown.yaml b/roles/cpu_pinning_operator/tasks/teardown.yaml new file mode 100644 index 00000000..5d02abad --- /dev/null +++ b/roles/cpu_pinning_operator/tasks/teardown.yaml @@ -0,0 +1,40 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# ============================================================================= +# CPU Pinning Operator — Teardown +# ============================================================================= +# `helm uninstall`, not label deletion: its hooks delete the guard webhook first +# (which would otherwise deny deleting the policy) and strip the operator's node +# labels after the manager is gone. + +- name: "cpu_pinning_operator | Uninstall Helm release" + kubernetes.core.helm: + name: "{{ cpu_pinning_operator_release }}" + release_namespace: "{{ cpu_pinning_operator_namespace }}" + state: absent + wait: true + timeout: "{{ helm_timeout }}" + +# Helm leaves CRDs. The NodeResourceTopology CRD stays: other topology +# exporters (NFD's topology-updater) share it. +- name: "cpu_pinning_operator | Delete the CRDs" + kubernetes.core.k8s: + state: absent + api_version: apiextensions.k8s.io/v1 + kind: CustomResourceDefinition + name: "{{ item }}" + wait: true + loop: + - balloonpinningpolicies.cpu-pinning-operator.intel.com + - balloonsclusterconfigs.cpu-pinning-operator.intel.com + - balloonspolicies.config.nri + +- name: "cpu_pinning_operator | Delete the namespace" + kubernetes.core.k8s: + state: absent + api_version: v1 + kind: Namespace + name: "{{ cpu_pinning_operator_namespace }}" + wait: true + wait_timeout: 300 diff --git a/roles/cpu_pinning_operator/tasks/validate.yaml b/roles/cpu_pinning_operator/tasks/validate.yaml new file mode 100644 index 00000000..9d3a6039 --- /dev/null +++ b/roles/cpu_pinning_operator/tasks/validate.yaml @@ -0,0 +1,46 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# ============================================================================= +# CPU Pinning Operator — Validate (read-only) +# ============================================================================= + +- name: "cpu_pinning_operator | Check the manager and the balloons plugin" + kubernetes.core.k8s_info: + api_version: apps/v1 + kind: "{{ item.kind }}" + name: "{{ item.name }}" + namespace: "{{ cpu_pinning_operator_namespace }}" + loop: + - {kind: Deployment, name: cpu-pinning-operator} + - {kind: DaemonSet, name: nri-resource-policy-balloons} + loop_control: + label: "{{ item.kind }}/{{ item.name }}" + register: _cpo_workloads + +- name: "cpu_pinning_operator | Assert they are ready" + ansible.builtin.assert: + that: + - item.resources | length > 0 + - (item.resources[0].status.readyReplicas | default(item.resources[0].status.numberReady) | default(0) | int) >= 1 + fail_msg: "{{ item.item.kind }}/{{ item.item.name }} has no ready pod in {{ cpu_pinning_operator_namespace }}" + quiet: true + loop: "{{ _cpo_workloads.results }}" + loop_control: + label: "{{ item.item.kind }}/{{ item.item.name }}" + +- name: "cpu_pinning_operator | Check BalloonsClusterConfig" + kubernetes.core.k8s_info: + api_version: cpu-pinning-operator.intel.com/v1alpha1 + kind: BalloonsClusterConfig + name: cluster + register: _cpo_bcc + +- name: "cpu_pinning_operator | Assert at least one node is provisioned" + ansible.builtin.assert: + that: + - _cpo_bcc.resources | length > 0 + - _cpo_bcc.resources[0].status.conditions | default([]) + | selectattr('type', 'eq', 'Ready') | selectattr('status', 'eq', 'True') | list | length > 0 + fail_msg: "BalloonsClusterConfig/cluster is not Ready: no node is provisioned for pinning" + success_msg: "CPU Pinning Operator is serving and pinning nodes" diff --git a/roles/cpu_pinning_operator/vars/kubernetes.yaml b/roles/cpu_pinning_operator/vars/kubernetes.yaml new file mode 100644 index 00000000..59fd2244 --- /dev/null +++ b/roles/cpu_pinning_operator/vars/kubernetes.yaml @@ -0,0 +1,7 @@ +--- +# Chart values that differ by platform. +_cpu_pinning_operator_platform_values: {} +# The Prometheus allowed to scrape the operator's authenticated metrics endpoint. +_cpu_pinning_operator_metrics_readers: + - name: kube-prometheus-stack-prometheus + namespace: "{{ observability_namespace | default('monitoring') }}" diff --git a/roles/cpu_pinning_operator/vars/openshift.yaml b/roles/cpu_pinning_operator/vars/openshift.yaml new file mode 100644 index 00000000..619a354e --- /dev/null +++ b/roles/cpu_pinning_operator/vars/openshift.yaml @@ -0,0 +1,12 @@ +--- +# The chart's values-openshift.yaml without its reserved sizing, which follows +# nri_deployment_profile here as on Kubernetes: the probe SCC, the plugin's SCC +# grant and openshift-* in the reserved pool. +_cpu_pinning_operator_platform_values: + openShift: {enabled: true} + balloonsClusterConfig: {balloon: {reservedNamespaces: ["kube-system", "openshift-*"]}} + nri-resource-policy-balloons: {openshift: {grant-scc: true}} +# User-workload monitoring's Prometheus. +_cpu_pinning_operator_metrics_readers: + - name: prometheus-user-workload + namespace: openshift-user-workload-monitoring diff --git a/roles/kubernetes/tasks/install_kubespray.yaml b/roles/kubernetes/tasks/install_kubespray.yaml index 6f9b2cc0..5660d5e2 100644 --- a/roles/kubernetes/tasks/install_kubespray.yaml +++ b/roles/kubernetes/tasks/install_kubespray.yaml @@ -107,5 +107,5 @@ | map(attribute='item') | zip(_kubelet_reserved_per_node.results | default([]) | map(attribute='stdout') | map('trim')) | map('join', '=') | join(' ') }} {%- else %} - n/a (managed by {{ 'nri_cpu_balloons' if (kubernetes_cpu_policy | default('nri-balloons')) == 'nri-balloons' else kubernetes_accelerator ~ ' scheduler' }}) + n/a (managed by {{ {'nri-balloons': 'nri_cpu_balloons', 'cpu-pinning-operator': 'cpu_pinning_operator'}.get(kubernetes_cpu_policy | default('nri-balloons'), kubernetes_accelerator ~ ' scheduler') }}) {%- endif %} diff --git a/roles/kubernetes/templates/kubespray_extra_auto.yml.j2 b/roles/kubernetes/templates/kubespray_extra_auto.yml.j2 index 1b956cc0..a488f941 100644 --- a/roles/kubernetes/templates/kubespray_extra_auto.yml.j2 +++ b/roles/kubernetes/templates/kubespray_extra_auto.yml.j2 @@ -24,6 +24,7 @@ bin_dir: "{{ kubespray_bin_dir_local }}" kubernetes_cpu_policy (resolved in playbooks/includes/preflight.yaml): nri-balloons default. kubelet stays cpuManagerPolicy=none; the nri_cpu_balloons role owns cpusets. Nothing emitted here. + cpu-pinning-operator as nri-balloons; cpu_pinning_operator owns them. kubelet-static kubelet static CPU manager gives Guaranteed-QoS pods exclusive whole cores. best-effort no pinning, but still reserve CPUs for system daemons. diff --git a/src/tests/unit/test_resolve_components.py b/src/tests/unit/test_resolve_components.py index 4ffb75d0..1dc8b527 100644 --- a/src/tests/unit/test_resolve_components.py +++ b/src/tests/unit/test_resolve_components.py @@ -203,3 +203,23 @@ def test_template_defaults_turn_on_headlamp_and_envoy_gateway_upgrade(): assert defaults["headlamp_enabled"] is True assert defaults["envoy_gateway_upgrade"] is True assert "llm_services_deploy_models" not in defaults + + +def test_cpu_pinning_operator_is_platform_after_cert_manager_and_observability(): + order = resolve_registry("platform", "install") + assert order.index("cert_manager") < order.index("cpu_pinning_operator") + assert order.index("observability") < order.index("cpu_pinning_operator") + assert "cpu_pinning_operator" not in resolve_registry("inference", "teardown") + + +@pytest.mark.parametrize("variables, nri, operator", [ + ({}, True, False), + ({"kubernetes_cpu_policy": "cpu-pinning-operator"}, False, True), + ({"kubernetes_cpu_policy": "cpu-pinning-operator", "kubernetes_accelerator": "xpu"}, False, True), + ({"kubernetes_accelerator": "xpu"}, False, False), + ({"kubernetes_cpu_policy": "best-effort"}, False, False), +]) +def test_cpu_policy_picks_one_balloons_installer(variables, nri, operator): + def on(name): + return _jinja().from_string(_component(name)["enabled"]).render(**variables) == "True" + assert (on("nri_cpu_balloons"), on("cpu_pinning_operator")) == (nri, operator)