Skip to content

Commit fbe0e06

Browse files
rollandfSchSeba
andcommitted
feat: DRA resource.k8s.io/v1 integration via draclient
Migrate Dynamic Resource Allocation from kubelet PodResources / v1alpha2-style usage to the stable resource.k8s.io/v1 API (Kubernetes 1.34+). - Add pkg/draclient: fetch ResourceClaims and ResourceSlices, build pod resource map from device attributes (k8s.cni.cncf.io/deviceID, k8s.cni.cncf.io/resourceName) and ExtendedResourceClaimStatus - Wire GetPodResourceMap into k8sclient; remove DRA path from kubeletclient - RBAC: resourceclaims, resourceclaims/status, resourceslices (get, list) on multus ClusterRole - Docs: DRA / NAD usage; tests for draclient and k8sclient Co-authored-by: Sebastian Sch <sebassch@gmail.com> Signed-off-by: Fred Rolland <frolland@nvidia.com>
1 parent 157e72f commit fbe0e06

12 files changed

Lines changed: 2453 additions & 116 deletions

deployments/multus-daemonset-crio.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ rules:
6969
- pods/status
7070
verbs:
7171
- get
72+
- list
7273
- update
74+
- watch
75+
- apiGroups:
76+
- "resource.k8s.io"
77+
resources:
78+
- resourceclaims
79+
- resourceclaims/status
80+
- resourceslices
81+
verbs:
82+
- get
83+
- list
7384
- apiGroups:
7485
- ""
7586
- events.k8s.io

deployments/multus-daemonset-thick.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ rules:
7272
- list
7373
- update
7474
- watch
75+
- apiGroups:
76+
- "resource.k8s.io"
77+
resources:
78+
- resourceclaims
79+
- resourceclaims/status
80+
- resourceslices
81+
verbs:
82+
- get
83+
- list
7584
- apiGroups:
7685
- ""
7786
- events.k8s.io

deployments/multus-daemonset.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ rules:
6969
- pods/status
7070
verbs:
7171
- get
72+
- list
7273
- update
74+
- watch
75+
- apiGroups:
76+
- "resource.k8s.io"
77+
resources:
78+
- resourceclaims
79+
- resourceclaims/status
80+
- resourceslices
81+
verbs:
82+
- get
83+
- list
7384
- apiGroups:
7485
- ""
7586
- events.k8s.io

docs/how-to-use.md

Lines changed: 94 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -645,112 +645,138 @@ If you wish to have auto configuration use the `readinessindicatorfile` in the c
645645

646646
### Run pod with network annotation and Dynamic Resource Allocation driver
647647

648-
> :warning: Dynamic Resource Allocation (DRA) is [currently an alpha](https://kubernetes.io/docs/concepts/scheduling-eviction/dynamic-resource-allocation/),
649-
> and is subject to change. Please consider this functionality as a preview. The architecture and usage of DRA in
650-
> Multus CNI may change in the future as this technology matures.
651-
>
652-
> The current DRA integration is based on the DRA API for Kubernetes 1.26 to 1.30. With Kubernetes 1.31, the DRA API
653-
> will change and multus doesn't integrate with the new API yet.
654648

655-
Dynamic Resource Allocation is alternative mechanism to device plugin which allows to requests pod and container
656-
resources.
649+
Dynamic Resource Allocation is an alternative mechanism to device plugin which allows pods to request pod and container
650+
resources dynamically.
657651

658-
The following sections describe how to use DRA with multus and NVIDIA DRA driver. Other DRA networking driver vendors
659-
should follow similar concepts to make use of multus DRA support.
652+
The following sections describe how to use DRA with Multus. DRA networking driver vendors should follow similar
653+
concepts to make use of Multus DRA support.
660654

661655
#### Prerequisite
662656

663-
1. Kubernetes 1.27
664-
2. Container Runtime with CDI support enabled
665-
3. Kubernetes runtime-config=resource.k8s.io/v1alpha2
666-
4. Kubernetes feature-gates=DynamicResourceAllocation=True,KubeletPodResourcesDynamicResources=true
657+
1. Kubernetes 1.34+
667658

668659
#### Install DRA driver
669660

670-
The current example uses NVIDIA DRA driver for networking. This DRA driver is not publicly available. An alternative to
671-
this DRA driver is available at [dra-example-driver](https://github.com/kubernetes-sigs/dra-example-driver).
661+
You need to install a DRA driver that provides network devices. For example, you can use the SR-IOV DRA driver or
662+
other DRA networking drivers. Refer to your DRA driver documentation for installation instructions.
672663

673-
#### Create dynamic resource class with NVIDIA network DRA driver
664+
The DRA driver MUST expose the following attributes on each allocated **device** in `ResourceSlice`:
665+
- `k8s.cni.cncf.io/deviceID`: device ID that Multus passes to the CNI plugin.
666+
- `k8s.cni.cncf.io/resourceName`: **must exactly match** the value you put on the NetworkAttachmentDefinition
667+
`k8s.v1.cni.cncf.io/resourceName` annotation (same style as classic extended resources, e.g. `intel.com/sriov_vf`).
668+
If `k8s.cni.cncf.io/resourceName` is missing on the device, allocation processing fails.
674669

675-
The `ResourceClass` defines the resource pool of `sf-pool-1`.
670+
For pods that use the **extended resource** feature gate, Multus uses `pod.status.extendedResourceClaimStatus`
671+
request mappings: the NAD `resourceName` matches `requestMappings[].resourceName` and device lookup uses the same
672+
`ResourceClaim` / `ResourceSlice` flow.
673+
674+
#### Create network attachment definition with resource name
675+
676+
The `k8s.v1.cni.cncf.io/resourceName` annotation must be the **same string** as the `k8s.cni.cncf.io/resourceName`
677+
device attribute published by your DRA driver for that allocation. Multiple secondary networks use distinct values
678+
on each device (or the same value when multiple device IDs should be consumed from one NAD, matching the device-plugin
679+
model).
680+
681+
Multus queries the ResourceClaim and ResourceSlices APIs. When the NAD annotation equals the device’s
682+
`k8s.cni.cncf.io/resourceName`, Multus passes the corresponding `k8s.cni.cncf.io/deviceID` to the CNI plugin.
683+
684+
##### NetworkAttachmentDefinition for SR-IOV example:
685+
686+
Following command creates a NetworkAttachmentDefinition for SR-IOV. The `resourceName` annotation must match what the
687+
DRA driver sets on the allocated device (here `intel.com/sriov_vf`):
676688

677689
```
678690
# Execute following command at Kubernetes master
679691
cat <<EOF | kubectl create -f -
680-
apiVersion: resource.k8s.io/v1alpha2
681-
kind: ResourceClass
692+
apiVersion: k8s.cni.cncf.io/v1
693+
kind: NetworkAttachmentDefinition
682694
metadata:
683-
name: sf-pool-1
684-
driverName: net.resource.nvidia.com
695+
name: sriov-net
696+
namespace: default
697+
annotations:
698+
k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_vf
699+
spec:
700+
config: |-
701+
{
702+
"cniVersion": "1.0.0",
703+
"name": "sriov-net",
704+
"type": "sriov",
705+
"vlan": 0,
706+
"spoofchk": "on",
707+
"trust": "on",
708+
"vlanQoS": 0,
709+
"logLevel": "info",
710+
"ipam": {
711+
"type": "host-local",
712+
"ranges": [
713+
[
714+
{
715+
"subnet": "10.0.2.0/24"
716+
}
717+
]
718+
]
719+
}
720+
}
685721
EOF
686722
```
687723

688-
#### Create network attachment definition with resource name
689-
690-
The `k8s.v1.cni.cncf.io/resourceName` should match the `ResourceClass` name defined in the section above.
691-
In this example it is `sf-pool-1`. Multus query the K8s PodResource API to fetch the `resourceClass` name and also
692-
query the NetworkAttachmentDefinition `k8s.v1.cni.cncf.io/resourceName`. If both has the same name multus send the
693-
CDI device name in the DeviceID argument.
724+
#### Create Device Class
694725

695-
##### NetworkAttachmentDefinition for ovn-kubernetes example:
696-
697-
Following command creates NetworkAttachmentDefinition. CNI config is in `config:` field.
726+
Following command creates a `DeviceClass` for the `ResourceClaimTemplate` to request devices from.
698727

699728
```
700729
# Execute following command at Kubernetes master
701730
cat <<EOF | kubectl create -f -
702-
apiVersion: "k8s.cni.cncf.io/v1"
703-
kind: NetworkAttachmentDefinition
731+
apiVersion: resource.k8s.io/v1
732+
kind: DeviceClass
704733
metadata:
705-
name: default
706-
annotations:
707-
k8s.v1.cni.cncf.io/resourceName: sf-pool-1
734+
name: sriovnetwork.openshift.io
708735
spec:
709-
config: '{
710-
"cniVersion": "0.4.0",
711-
"dns": {},
712-
"ipam": {},
713-
"logFile": "/var/log/ovn-kubernetes/ovn-k8s-cni-overlay.log",
714-
"logLevel": "4",
715-
"logfile-maxage": 5,
716-
"logfile-maxbackups": 5,
717-
"logfile-maxsize": 100,
718-
"name": "ovn-kubernetes",
719-
"type": "ovn-k8s-cni-overlay"
720-
}'
736+
selectors:
737+
- cel:
738+
expression: device.driver == sriovnetwork.openshift.io
721739
EOF
722740
```
723741

724-
#### Create DRA Resource Claim
742+
#### Create DRA Resource Claim Template
725743

726-
Following command creates `ResourceClaim` `sf` which request resource from `ResourceClass` `sf-pool-1`.
744+
Following command creates a `ResourceClaimTemplate` that requests a VF device from the SR-IOV device class.
745+
The device request is named `vf`; the DRA driver should publish `k8s.cni.cncf.io/resourceName` on the device
746+
so it matches your NAD (e.g. `intel.com/sriov_vf`).
727747

728748
```
729749
# Execute following command at Kubernetes master
730750
cat <<EOF | kubectl create -f -
731-
apiVersion: resource.k8s.io/v1alpha2
732-
kind: ResourceClaim
751+
apiVersion: resource.k8s.io/v1
752+
kind: ResourceClaimTemplate
733753
metadata:
734754
namespace: default
735-
name: sf
755+
name: sriov-template
736756
spec:
737757
spec:
738-
resourceClassName: sf-pool-1
758+
devices:
759+
requests:
760+
- name: vf
761+
deviceClassName: sriovnetwork.openshift.io
739762
EOF
740763
```
741764

742765
#### Launch pod with DRA Resource Claim
743766

744-
Following command Launch a Pod with primiry network `default` and `ResourceClaim` `sf`.
767+
Following command launches a Pod with the secondary network `sriov-net` and a DRA resource claim named `sriov`.
768+
The NAD `resourceName` must match the driver’s `k8s.cni.cncf.io/resourceName` on the allocated device.
745769

746770
```
771+
# Execute following command at Kubernetes master
772+
cat <<EOF | kubectl create -f -
747773
apiVersion: v1
748774
kind: Pod
749775
metadata:
750776
namespace: default
751-
name: test-sf-claim
777+
name: sriov-pod
752778
annotations:
753-
v1.multus-cni.io/default-network: default
779+
k8s.v1.cni.cncf.io/networks: sriov-net
754780
spec:
755781
restartPolicy: Always
756782
containers:
@@ -759,9 +785,16 @@ spec:
759785
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
760786
resources:
761787
claims:
762-
- name: resource
788+
- name: sriov
763789
resourceClaims:
764-
- name: resource
765-
source:
766-
resourceClaimName: sf
790+
- name: sriov
791+
resourceClaimTemplateName: sriov-template
792+
EOF
767793
```
794+
795+
In this example:
796+
- The pod has a resourceClaim named `sriov` that uses the `sriov-template`
797+
- The ResourceClaimTemplate has a device request named `vf`
798+
- The DRA driver must set `k8s.cni.cncf.io/resourceName: intel.com/sriov_vf` (and `deviceID`) on the allocated device
799+
- The NetworkAttachmentDefinition uses `resourceName: intel.com/sriov_vf` to match that device attribute
800+
- Multus will match these and provide the allocated deviceID to the SR-IOV CNI plugin

0 commit comments

Comments
 (0)