Skip to content

Commit 52d399b

Browse files
authored
Merge pull request #69 from rollandf/rename
Decouple device attributes from policy with new DeviceAttributes CRD
2 parents 859c557 + 7c9b900 commit 52d399b

23 files changed

+1991
-956
lines changed

README.md

Lines changed: 86 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ The driver features an advanced resource filtering system that enables administr
1515
## Features
1616

1717
- **Dynamic Resource Allocation**: Leverages Kubernetes DRA framework for SR-IOV VF management
18-
- **Advanced Resource Filtering**: Fine-grained filtering of Virtual Functions based on hardware attributes
19-
- **Custom Resource Definitions**: SriovResourceFilter CRD for configuring device filtering policies
20-
- **Controller-based Management**: Kubernetes controller pattern for resource filter lifecycle management
18+
- **Opt-In Device Advertisement**: Devices are only advertised when explicitly defined in a policy
19+
- **Custom Resource Definitions**:
20+
- SriovResourcePolicy CRD for configuring device advertisement policies
21+
- DeviceAttributes CRD defines a set of arbitrary attributes that can be applied to devices selected by a SriovResourcePolicy. Policies reference DeviceAttributes objects via label selectors.
22+
- **Controller-based Management**: Kubernetes controller pattern for resource policy lifecycle management
2123
- **Multiple Resource Types**: Support for exposing different VF pools as distinct resource types
22-
- **Node-targeted Filtering**: Per-node resource filtering with node selector support
24+
- **Node-targeted Policies**: Per-node resource policies with node selector support
2325
- **CDI Integration**: Uses Container Device Interface for device injection into containers
2426
- **NRI Integration**: Node Resource Interface support for advanced container runtime interaction
2527
- **Kubernetes Native**: Integrates seamlessly with standard Kubernetes resource request/limit model
@@ -79,7 +81,7 @@ The Helm chart supports various configuration options through `values.yaml`:
7981
- **Image Configuration**: Customize image repository, tag, and pull policy
8082
- **Resource Limits**: Set resource requests and limits for driver components
8183
- **Node Selection**: Configure node selectors and tolerations
82-
- **Namespace Configuration**: Configure the namespace where SriovResourceFilter resources are watched
84+
- **Namespace Configuration**: Configure the namespace where SriovResourcePolicy resources are watched
8385
- **Default Interface Prefix**: Set the default interface prefix for virtual functions
8486
- **CDI Root**: Configure the directory for CDI file generation
8587
- **Logging**: Adjust log verbosity and format
@@ -137,33 +139,72 @@ spec:
137139
138140
## Resource Filtering System
139141
140-
The DRA driver includes an advanced resource filtering system that allows administrators to define fine-grained policies for how SR-IOV Virtual Functions are exposed and allocated. This system uses Custom Resource Definitions (CRDs) and a Kubernetes controller to manage device filtering based on hardware characteristics.
142+
The DRA driver uses an opt-in model where administrators explicitly define which SR-IOV Virtual Functions should be advertised as Kubernetes resources. This system uses Custom Resource Definitions (CRDs) and a Kubernetes controller to manage device advertisement policies based on hardware characteristics.
141143
142-
### SriovResourceFilter CRD
144+
**Important**: Without a matching `SriovResourcePolicy`, no devices will be advertised.
143145

144-
The `SriovResourceFilter` custom resource allows you to define filtering policies for SR-IOV devices:
146+
### SriovResourcePolicy CRD
147+
148+
The `SriovResourcePolicy` custom resource defines which SR-IOV devices should be advertised as allocatable resources. Attributes are decoupled into a separate `DeviceAttributes` CRD and linked via label selectors:
145149

146150
```yaml
151+
# 1. Define attributes to apply to matched devices
152+
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
153+
kind: DeviceAttributes
154+
metadata:
155+
name: eth0-attrs
156+
namespace: dra-sriov-driver
157+
labels:
158+
pool: eth0-resource
159+
spec:
160+
attributes:
161+
sriovnetwork.k8snetworkplumbingwg.io/resourceName:
162+
string: "eth0_resource"
163+
---
164+
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
165+
kind: DeviceAttributes
166+
metadata:
167+
name: eth1-attrs
168+
namespace: dra-sriov-driver
169+
labels:
170+
pool: eth1-resource
171+
spec:
172+
attributes:
173+
sriovnetwork.k8snetworkplumbingwg.io/resourceName:
174+
string: "eth1_resource"
175+
---
176+
# 2. Policy selects devices and references attributes by label
147177
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
148-
kind: SriovResourceFilter
178+
kind: SriovResourcePolicy
149179
metadata:
150-
name: example-filter
180+
name: example-policy
151181
namespace: dra-sriov-driver
152182
spec:
153183
nodeSelector:
154-
kubernetes.io/hostname: worker-node-1
184+
nodeSelectorTerms:
185+
- matchExpressions:
186+
- key: kubernetes.io/hostname
187+
operator: In
188+
values:
189+
- worker-node-1
155190
configs:
156-
- resourceName: "eth0_resource"
191+
- deviceAttributesSelector:
192+
matchLabels:
193+
pool: eth0-resource
157194
resourceFilters:
158195
- vendors: ["8086"] # Intel devices only
159196
pfNames: ["eth0"] # Physical Function name
160-
- resourceName: "eth1_resource"
161-
resourceFilters:
197+
- deviceAttributesSelector:
198+
matchLabels:
199+
pool: eth1-resource
200+
resourceFilters:
162201
- vendors: ["8086"]
163202
pfNames: ["eth1"]
164203
drivers: ["vfio-pci"] # Only VFIO-bound devices
165204
```
166205

206+
Each `Config` entry pairs a `deviceAttributesSelector` (label selector matching `DeviceAttributes` objects) with `resourceFilters` (device hardware criteria). Devices matching the filters are advertised, and attributes from all matching `DeviceAttributes` objects are merged onto them.
207+
167208
### Filtering Criteria
168209

169210
The resource filtering system supports multiple filtering criteria that can be combined:
@@ -173,40 +214,48 @@ The resource filtering system supports multiple filtering criteria that can be c
173214
- **pciAddresses**: Filter by specific PCI addresses
174215
- **pfNames**: Filter by Physical Function name (e.g., "eth0", "eth1")
175216
- **pfPciAddresses**: Filter by Physical Function PCI address
217+
- **drivers**: Filter by bound driver name (e.g., "vfio-pci", "igb_uio")
176218

177219
### Node Selection
178220

179-
Use `nodeSelector` to target specific nodes:
221+
Use `nodeSelector` (a `v1.NodeSelector`) to target specific nodes. Omit it to match all nodes:
180222

181223
```yaml
182224
spec:
183225
nodeSelector:
184-
kubernetes.io/hostname: specific-node
185-
# or
186-
node-type: sriov-enabled
187-
# Empty nodeSelector matches all nodes
226+
nodeSelectorTerms:
227+
- matchExpressions:
228+
- key: kubernetes.io/hostname
229+
operator: In
230+
values:
231+
- specific-node
232+
# Multiple terms are ORed; expressions within a term are ANDed
188233
```
189234

190235
### Multiple Resource Types
191236

192-
Define multiple resource configurations to create different pools of Virtual Functions:
237+
Define multiple configs to create different pools of Virtual Functions, each referencing a `DeviceAttributes` object via label selector:
193238

194239
```yaml
195240
spec:
196241
configs:
197-
- resourceName: "high-performance"
242+
- deviceAttributesSelector:
243+
matchLabels:
244+
pool: high-performance
198245
resourceFilters:
199246
- vendors: ["8086"]
200247
pfNames: ["eth0"]
201-
- resourceName: "standard-networking"
248+
- deviceAttributesSelector:
249+
matchLabels:
250+
pool: standard-networking
202251
resourceFilters:
203-
- vendors: ["8086"]
252+
- vendors: ["8086"]
204253
pfNames: ["eth1"]
205254
```
206255

207-
### Using Filtered Resources
256+
### Using Policy-Defined Resources
208257

209-
Once a `SriovResourceFilter` is applied, pods can request specific resource types using CEL expressions:
258+
Once a `SriovResourcePolicy` is applied, devices matching the policy are advertised and pods can request specific resource types using CEL expressions:
210259

211260
```yaml
212261
apiVersion: resource.k8s.io/v1
@@ -299,11 +348,11 @@ Demonstrates requesting multiple Virtual Functions in a single resource claim:
299348
- VfConfig applies to all allocated VFs in the claim
300349
- Automatic interface naming (typically net1, net2, etc.)
301350

302-
#### Resource Filtering (`demo/resource-filtering/`)
303-
Shows how to use SriovResourceFilter for advanced device management:
304-
- Filter VFs based on vendor ID, Physical Function names, and hardware attributes
351+
#### Resource Policies (`demo/resource-policies/`)
352+
Shows how to use SriovResourcePolicy for controlling device advertisement:
353+
- Advertise VFs based on vendor ID, Physical Function names, and hardware attributes
305354
- Multiple resource configurations for different network interfaces
306-
- Node-targeted filtering with selector support
355+
- Node-targeted policies with selector support
307356

308357
#### VFIO Driver Configuration (`demo/vfio-driver/`)
309358
Illustrates VFIO-PCI driver configuration for userspace applications:
@@ -323,10 +372,10 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
323372
│ └── dra-driver-sriov/ # Main driver executable
324373
├── pkg/
325374
│ ├── driver/ # Core driver implementation
326-
│ ├── controller/ # Kubernetes controller for resource filtering
375+
│ ├── controller/ # Kubernetes controller for resource policies
327376
│ ├── devicestate/ # Device state management and discovery
328377
│ ├── api/ # API definitions
329-
│ │ ├── sriovdra/v1alpha1/ # SriovResourceFilter CRD definitions
378+
│ │ ├── sriovdra/v1alpha1/ # SriovResourcePolicy and DeviceAttributes CRD definitions
330379
│ │ └── virtualfunction/v1alpha1/ # Virtual Function API types
331380
│ ├── cdi/ # CDI integration
332381
│ ├── cni/ # CNI plugin integration
@@ -342,8 +391,8 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
342391
├── demo/ # Example workload configurations
343392
│ ├── single-vf-claim/ # Single VF allocation example
344393
│ ├── multiple-vf-claim/ # Multiple VF allocation example
345-
│ ├── resource-filtering/ # Resource filtering configuration example
346-
│ └── vfio-driver/ # VFIO-PCI driver configuration example
394+
│ ├── resource-policies/ # Resource policy configuration example
395+
│ └── vfio-driver/ # VFIO-PCI driver configuration example
347396
├── hack/ # Build and development scripts
348397
├── test/ # Test suites
349398
└── vendor/ # Go module dependencies
@@ -352,9 +401,10 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
352401
### Key Components
353402
354403
- **Driver**: Main gRPC service implementing DRA kubelet plugin interface
355-
- **Resource Filter Controller**: Kubernetes controller managing SriovResourceFilter lifecycle and device filtering
356-
- **Device State Manager**: Tracks available and allocated SR-IOV virtual functions with filtering support
357-
- **SriovResourceFilter CRD**: Custom resource for defining device filtering policies
404+
- **Resource Policy Controller**: Kubernetes controller managing SriovResourcePolicy lifecycle and device advertisement
405+
- **Device State Manager**: Tracks available and allocated SR-IOV virtual functions
406+
- **SriovResourcePolicy CRD**: Custom resource for defining device advertisement policies (opt-in model)
407+
- **DeviceAttributes CRD**: Custom resource for defining arbitrary attributes applied to policy-matched devices via label selectors
358408
- **CDI Generator**: Creates Container Device Interface specifications for VFs
359409
- **NRI Plugin**: Node Resource Interface integration for container runtime interaction
360410
- **Pod Manager**: Manages pod lifecycle and resource allocation

cmd/dra-driver-sriov/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func newApp() *cli.App {
8686
},
8787
&cli.StringFlag{
8888
Name: "namespace",
89-
Usage: "Namespace where the driver should watch for SriovResourceFilter resources.",
89+
Usage: "Namespace where the driver should watch for SriovResourcePolicy resources.",
9090
Value: "dra-sriov-driver",
9191
Destination: &flagsOptions.Namespace,
9292
EnvVars: []string{"NAMESPACE"},
@@ -188,11 +188,11 @@ func RunPlugin(ctx context.Context, config *types.Config) error {
188188

189189
logger.Info("Configuring controller manager", "namespace", config.Flags.Namespace)
190190

191-
// Configure cache to only watch resources in the specified namespace for SriovResourceFilter
191+
// Configure cache to only watch resources in the specified namespace for SriovResourcePolicy
192192
// while allowing cluster-wide access for other resources like Nodes
193193
cacheOpts := cache.Options{
194194
ByObject: map[client.Object]cache.ByObject{
195-
&sriovdrav1alpha1.SriovResourceFilter{}: {
195+
&sriovdrav1alpha1.SriovResourcePolicy{}: {
196196
Namespaces: map[string]cache.Config{
197197
config.Flags.Namespace: {},
198198
},
@@ -209,10 +209,10 @@ func RunPlugin(ctx context.Context, config *types.Config) error {
209209
return fmt.Errorf("failed to create controller manager: %w", err)
210210
}
211211

212-
// create and setup resource filter controller
213-
resourceFilterController := controller.NewSriovResourceFilterReconciler(config.K8sClient.Client, config.Flags.NodeName, config.Flags.Namespace, deviceStateManager)
214-
if err := resourceFilterController.SetupWithManager(mgr); err != nil {
215-
return fmt.Errorf("failed to setup resource filter controller: %w", err)
212+
// create and setup resource policy controller
213+
resourcePolicyController := controller.NewSriovResourcePolicyReconciler(config.K8sClient.Client, config.Flags.NodeName, config.Flags.Namespace, deviceStateManager)
214+
if err := resourcePolicyController.SetupWithManager(mgr); err != nil {
215+
return fmt.Errorf("failed to setup resource policy controller: %w", err)
216216
}
217217

218218
// start controller manager

demo/extended-resource/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ In both cases, the scheduler transparently creates a ResourceClaim with an `Exac
2121

2222
## Components
2323

24-
### 1. SriovResourceFilter (Dual-Port)
25-
The `SriovResourceFilter` defines two resource groups — one per physical NIC port:
24+
### 1. SriovResourcePolicy (Dual-Port)
25+
The `SriovResourcePolicy` defines two resource groups — one per physical NIC port:
2626
- **port1-vfs**: VFs on PCI bus `08:00.{2,3,4,5}`
2727
- **port2-vfs**: VFs on PCI bus `08:02.{2,3,4,5}`
2828

@@ -52,7 +52,7 @@ Pods use standard `resources.requests` / `resources.limits` — no `resourceClai
5252
deviceclass.yaml
5353
┌──────────────────────────────────────────────────────────┐
5454
│ │
55-
SriovResourceFilter "dual-port-vfs" │
55+
SriovResourcePolicy "dual-port-vfs" │
5656
│ ┌───────────────────┐ ┌───────────────────┐ │
5757
│ │ port1-vfs │ │ port2-vfs │ │
5858
│ │ 08:00.{2,3,4,5} │ │ 08:02.{2,3,4,5} │ │
@@ -91,7 +91,7 @@ Extended resource allocation is ideal for:
9191

9292
## Usage
9393

94-
1. Deploy the DeviceClasses, SriovResourceFilter, and NetworkAttachmentDefinitions:
94+
1. Deploy the DeviceClasses, SriovResourcePolicy, and NetworkAttachmentDefinitions:
9595
```bash
9696
kubectl apply -f deviceclass.yaml
9797
```
@@ -167,7 +167,7 @@ The other demos in this repository (`single-vf-claim/`, `resourceclaim/`, `vfio-
167167

168168
### Changing PCI Addresses
169169

170-
Update the `SriovResourceFilter` in `deviceclass.yaml` with your actual VF PCI addresses:
170+
Update the `SriovResourcePolicy` in `deviceclass.yaml` with your actual VF PCI addresses:
171171

172172
```bash
173173
# Find VF PCI addresses on your host

demo/extended-resource/deviceclass.yaml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
1-
# SriovResourceFilter with two configs — one per physical port
1+
# DeviceAttributes for port 1
22
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
3-
kind: SriovResourceFilter
3+
kind: DeviceAttributes
4+
metadata:
5+
name: port1-attrs
6+
namespace: dra-sriov-driver
7+
labels:
8+
pool: port1-vfs
9+
spec:
10+
attributes:
11+
sriovnetwork.k8snetworkplumbingwg.io/resourceName:
12+
string: "port1-vfs"
13+
---
14+
# DeviceAttributes for port 2
15+
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
16+
kind: DeviceAttributes
17+
metadata:
18+
name: port2-attrs
19+
namespace: dra-sriov-driver
20+
labels:
21+
pool: port2-vfs
22+
spec:
23+
attributes:
24+
sriovnetwork.k8snetworkplumbingwg.io/resourceName:
25+
string: "port2-vfs"
26+
---
27+
# SriovResourcePolicy with two configs — one per physical port
28+
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
29+
kind: SriovResourcePolicy
430
metadata:
531
name: dual-port-vfs
6-
namespace: dra-sriov-system
32+
namespace: dra-sriov-driver
733
spec:
8-
nodeSelector: {}
934
configs:
10-
- resourceName: "port1-vfs"
35+
- deviceAttributesSelector:
36+
matchLabels:
37+
pool: port1-vfs
1138
resourceFilters:
1239
- pciAddresses:
1340
- "0000:08:00.2"
1441
- "0000:08:00.3"
1542
- "0000:08:00.4"
1643
- "0000:08:00.5"
17-
- resourceName: "port2-vfs"
44+
- deviceAttributesSelector:
45+
matchLabels:
46+
pool: port2-vfs
1847
resourceFilters:
1948
- pciAddresses:
2049
- "0000:08:02.2"

0 commit comments

Comments
 (0)