Skip to content

Commit 25483d2

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 25483d2

12 files changed

Lines changed: 2587 additions & 117 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: 95 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -645,112 +645,139 @@ 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`. The device attribute
672+
`k8s.cni.cncf.io/resourceName` must be set and must **equal** that same `requestMappings[].resourceName` value
673+
(Multus rejects a mismatch). Device lookup uses the same `ResourceClaim` / `ResourceSlice` flow.
674+
675+
#### Create network attachment definition with resource name
676+
677+
The `k8s.v1.cni.cncf.io/resourceName` annotation must be the **same string** as the `k8s.cni.cncf.io/resourceName`
678+
device attribute published by your DRA driver for that allocation. Multiple secondary networks use distinct values
679+
on each device (or the same value when multiple device IDs should be consumed from one NAD, matching the device-plugin
680+
model).
681+
682+
Multus queries the ResourceClaim and ResourceSlices APIs. When the NAD annotation equals the device’s
683+
`k8s.cni.cncf.io/resourceName`, Multus passes the corresponding `k8s.cni.cncf.io/deviceID` to the CNI plugin.
684+
685+
##### NetworkAttachmentDefinition for SR-IOV example:
686+
687+
Following command creates a NetworkAttachmentDefinition for SR-IOV. The `resourceName` annotation must match what the
688+
DRA driver sets on the allocated device (here `intel.com/sriov_vf`):
676689

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

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.
725+
#### Create Device Class
694726

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

699729
```
700730
# Execute following command at Kubernetes master
701731
cat <<EOF | kubectl create -f -
702-
apiVersion: "k8s.cni.cncf.io/v1"
703-
kind: NetworkAttachmentDefinition
732+
apiVersion: resource.k8s.io/v1
733+
kind: DeviceClass
704734
metadata:
705-
name: default
706-
annotations:
707-
k8s.v1.cni.cncf.io/resourceName: sf-pool-1
735+
name: sriovnetwork.openshift.io
708736
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-
}'
737+
selectors:
738+
- cel:
739+
expression: device.driver == sriovnetwork.openshift.io
721740
EOF
722741
```
723742

724-
#### Create DRA Resource Claim
743+
#### Create DRA Resource Claim Template
725744

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

728749
```
729750
# Execute following command at Kubernetes master
730751
cat <<EOF | kubectl create -f -
731-
apiVersion: resource.k8s.io/v1alpha2
732-
kind: ResourceClaim
752+
apiVersion: resource.k8s.io/v1
753+
kind: ResourceClaimTemplate
733754
metadata:
734755
namespace: default
735-
name: sf
756+
name: sriov-template
736757
spec:
737758
spec:
738-
resourceClassName: sf-pool-1
759+
devices:
760+
requests:
761+
- name: vf
762+
deviceClassName: sriovnetwork.openshift.io
739763
EOF
740764
```
741765

742766
#### Launch pod with DRA Resource Claim
743767

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

746771
```
772+
# Execute following command at Kubernetes master
773+
cat <<EOF | kubectl create -f -
747774
apiVersion: v1
748775
kind: Pod
749776
metadata:
750777
namespace: default
751-
name: test-sf-claim
778+
name: sriov-pod
752779
annotations:
753-
v1.multus-cni.io/default-network: default
780+
k8s.v1.cni.cncf.io/networks: sriov-net
754781
spec:
755782
restartPolicy: Always
756783
containers:
@@ -759,9 +786,16 @@ spec:
759786
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
760787
resources:
761788
claims:
762-
- name: resource
789+
- name: sriov
763790
resourceClaims:
764-
- name: resource
765-
source:
766-
resourceClaimName: sf
791+
- name: sriov
792+
resourceClaimTemplateName: sriov-template
793+
EOF
767794
```
795+
796+
In this example:
797+
- The pod has a resourceClaim named `sriov` that uses the `sriov-template`
798+
- The ResourceClaimTemplate has a device request named `vf`
799+
- The DRA driver must set `k8s.cni.cncf.io/resourceName: intel.com/sriov_vf` (and `deviceID`) on the allocated device
800+
- The NetworkAttachmentDefinition uses `resourceName: intel.com/sriov_vf` to match that device attribute
801+
- Multus will match these and provide the allocated deviceID to the SR-IOV CNI plugin

0 commit comments

Comments
 (0)