Skip to content

Commit 7f7458d

Browse files
committed
Rename SriovResourceFilter to SriovResourcePolicy
Changes API naming to better reflect the opt-in policy-based approach where devices are only advertised when explicitly defined in a policy. - Rename API types and CRD - Update controller: resourcefiltercontroller.go → resourcepolicycontroller.go - Update RBAC, demo examples, and tests - Update documentation with opt-in model terminology Part of #23 Signed-off-by: Fred Rolland <frolland@nvidia.com>
1 parent 551f924 commit 7f7458d

File tree

11 files changed

+205
-199
lines changed

11 files changed

+205
-199
lines changed

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ 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**: SriovResourcePolicy CRD for configuring device advertisement policies
20+
- **Controller-based Management**: Kubernetes controller pattern for resource policy lifecycle management
2121
- **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
22+
- **Node-targeted Policies**: Per-node resource policies with node selector support
2323
- **CDI Integration**: Uses Container Device Interface for device injection into containers
2424
- **NRI Integration**: Node Resource Interface support for advanced container runtime interaction
2525
- **Kubernetes Native**: Integrates seamlessly with standard Kubernetes resource request/limit model
@@ -79,7 +79,7 @@ The Helm chart supports various configuration options through `values.yaml`:
7979
- **Image Configuration**: Customize image repository, tag, and pull policy
8080
- **Resource Limits**: Set resource requests and limits for driver components
8181
- **Node Selection**: Configure node selectors and tolerations
82-
- **Namespace Configuration**: Configure the namespace where SriovResourceFilter resources are watched
82+
- **Namespace Configuration**: Configure the namespace where SriovResourcePolicy resources are watched
8383
- **Default Interface Prefix**: Set the default interface prefix for virtual functions
8484
- **CDI Root**: Configure the directory for CDI file generation
8585
- **Logging**: Adjust log verbosity and format
@@ -137,17 +137,19 @@ spec:
137137
138138
## Resource Filtering System
139139
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.
140+
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.
141141
142-
### SriovResourceFilter CRD
142+
**Important**: Without a matching `SriovResourcePolicy`, no devices will be advertised.
143143

144-
The `SriovResourceFilter` custom resource allows you to define filtering policies for SR-IOV devices:
144+
### SriovResourcePolicy CRD
145+
146+
The `SriovResourcePolicy` custom resource defines which SR-IOV devices should be advertised as allocatable resources:
145147

146148
```yaml
147149
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
148-
kind: SriovResourceFilter
150+
kind: SriovResourcePolicy
149151
metadata:
150-
name: example-filter
152+
name: example-policy
151153
namespace: dra-sriov-driver
152154
spec:
153155
nodeSelector:
@@ -207,9 +209,9 @@ spec:
207209
pfNames: ["eth1"]
208210
```
209211

210-
### Using Filtered Resources
212+
### Using Policy-Defined Resources
211213

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

214216
```yaml
215217
apiVersion: resource.k8s.io/v1
@@ -302,11 +304,11 @@ Demonstrates requesting multiple Virtual Functions in a single resource claim:
302304
- VfConfig applies to all allocated VFs in the claim
303305
- Automatic interface naming (typically net1, net2, etc.)
304306

305-
#### Resource Filtering (`demo/resource-filtering/`)
306-
Shows how to use SriovResourceFilter for advanced device management:
307-
- Filter VFs based on vendor ID, Physical Function names, and hardware attributes
307+
#### Resource Policies (`demo/resource-policies/`)
308+
Shows how to use SriovResourcePolicy for controlling device advertisement:
309+
- Advertise VFs based on vendor ID, Physical Function names, and hardware attributes
308310
- Multiple resource configurations for different network interfaces
309-
- Node-targeted filtering with selector support
311+
- Node-targeted policies with selector support
310312

311313
#### VFIO Driver Configuration (`demo/vfio-driver/`)
312314
Illustrates VFIO-PCI driver configuration for userspace applications:
@@ -326,10 +328,10 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
326328
│ └── dra-driver-sriov/ # Main driver executable
327329
├── pkg/
328330
│ ├── driver/ # Core driver implementation
329-
│ ├── controller/ # Kubernetes controller for resource filtering
331+
│ ├── controller/ # Kubernetes controller for resource policies
330332
│ ├── devicestate/ # Device state management and discovery
331333
│ ├── api/ # API definitions
332-
│ │ ├── sriovdra/v1alpha1/ # SriovResourceFilter CRD definitions
334+
│ │ ├── sriovdra/v1alpha1/ # SriovResourcePolicy CRD definitions
333335
│ │ └── virtualfunction/v1alpha1/ # Virtual Function API types
334336
│ ├── cdi/ # CDI integration
335337
│ ├── cni/ # CNI plugin integration
@@ -345,7 +347,7 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
345347
├── demo/ # Example workload configurations
346348
│ ├── single-vf-claim/ # Single VF allocation example
347349
│ ├── multiple-vf-claim/ # Multiple VF allocation example
348-
│ ├── resource-filtering/ # Resource filtering configuration example
350+
│ ├── resource-policies/ # Resource policy configuration example
349351
│ └── vfio-driver/ # VFIO-PCI driver configuration example
350352
├── hack/ # Build and development scripts
351353
├── test/ # Test suites
@@ -355,9 +357,9 @@ Illustrates VFIO-PCI driver configuration for userspace applications:
355357
### Key Components
356358
357359
- **Driver**: Main gRPC service implementing DRA kubelet plugin interface
358-
- **Resource Filter Controller**: Kubernetes controller managing SriovResourceFilter lifecycle and device filtering
359-
- **Device State Manager**: Tracks available and allocated SR-IOV virtual functions with filtering support
360-
- **SriovResourceFilter CRD**: Custom resource for defining device filtering policies
360+
- **Resource Policy Controller**: Kubernetes controller managing SriovResourcePolicy lifecycle and device advertisement
361+
- **Device State Manager**: Tracks available and allocated SR-IOV virtual functions
362+
- **SriovResourcePolicy CRD**: Custom resource for defining device advertisement policies (opt-in model)
361363
- **CDI Generator**: Creates Container Device Interface specifications for VFs
362364
- **NRI Plugin**: Node Resource Interface integration for container runtime interaction
363365
- **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
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Resource Filtering Demo
1+
# Resource Policy Demo
22

3-
This demo showcases how to use `SriovResourceFilter` to filter and manage SR-IOV Virtual Functions based on various hardware and configuration criteria.
3+
This demo showcases how to use `SriovResourcePolicy` to control which SR-IOV Virtual Functions are advertised as Kubernetes resources based on various hardware and configuration criteria.
44

55
## Overview
66

77
This scenario demonstrates:
8-
- Creating resource filters based on vendor IDs, Physical Function names, and other hardware attributes
8+
- Creating resource policies based on vendor IDs, Physical Function names, and other hardware attributes
99
- Setting up multiple resource configurations for different network interfaces
10-
- Deploying a pod that uses filtered SR-IOV resources with specific network requirements
10+
- Deploying a pod that uses policy-filtered SR-IOV resources with specific network requirements
1111

1212
## Components
1313

14-
### 1. SriovResourceFilter
15-
The `SriovResourceFilter` resource defines how to filter available SR-IOV devices:
14+
### 1. SriovResourcePolicy
15+
The `SriovResourcePolicy` resource defines which SR-IOV devices should be advertised as allocatable resources:
1616
- **nodeSelector**: Targets specific nodes (`dra-ctlplane-0.dra.lab` in this example)
1717
- **configs**: Defines multiple resource configurations:
1818
- `eth0_resource`: Filters devices connected to eth0 Physical Function
@@ -39,17 +39,20 @@ The `SriovResourceFilter` resource defines how to filter available SR-IOV device
3939

4040
## Usage
4141

42-
1. Apply the resource filter to make filtered resources available:
42+
1. Apply the resource policy to advertise SR-IOV resources:
4343
```bash
44-
kubectl apply -f resource-filter.yaml
44+
kubectl apply -f resource-policy.yaml
4545
```
4646

47-
2. The DRA driver will discover and filter SR-IOV devices based on the criteria
48-
3. Pods can then claim resources using the filtered resource names
47+
2. The DRA driver will discover SR-IOV devices and advertise only those matching the policy criteria
48+
3. Pods can then claim resources using the advertised resource names
4949
4. The pod will be scheduled on nodes where matching resources are available
5050

51+
**Note**: Without a matching `SriovResourcePolicy`, no devices will be advertised (opt-in model).
52+
5153
## Key Features
5254

55+
- **Opt-In Model**: Devices are only advertised when explicitly defined in a policy
5356
- **Granular Filtering**: Filter by vendor, device ID, PCI address, PF name, NUMA node, or driver
5457
- **Multi-Resource Support**: Configure multiple resource types on the same node
5558
- **CEL Integration**: Use Common Expression Language for advanced resource selection

demo/resource-filtering/resource-filter.yaml renamed to demo/resource-policies/resource-policy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: sriovnetwork.k8snetworkplumbingwg.io/v1alpha1
2-
kind: SriovResourceFilter
2+
kind: SriovResourcePolicy
33
metadata:
4-
name: example-resource-filter
4+
name: example-resource-policy
55
namespace: dra-sriov-driver
66
spec:
77
# NodeSelector to match specific nodes

deployments/helm/dra-driver-sriov/templates/clusterrole.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ rules:
2121
resources: ["network-attachment-definitions"]
2222
verbs: ["get"]
2323
- apiGroups: ["sriovnetwork.k8snetworkplumbingwg.io"]
24-
resources: ["sriovresourcefilters"]
25-
verbs: ["get", "list", "watch"] # SriovResourceFilter resources
24+
resources: ["sriovresourcepolicies"]
25+
verbs: ["get", "list", "watch"] # SriovResourcePolicy resources

deployments/helm/dra-driver-sriov/templates/sriovnetwork.k8snetworkplumbingwg.io_sriovresourcefilters.yaml renamed to deployments/helm/dra-driver-sriov/templates/sriovnetwork.k8snetworkplumbingwg.io_sriovresourcepolicies.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.20.0
7-
name: sriovresourcefilters.sriovnetwork.k8snetworkplumbingwg.io
7+
name: sriovresourcepolicies.sriovnetwork.k8snetworkplumbingwg.io
88
spec:
99
group: sriovnetwork.k8snetworkplumbingwg.io
1010
names:
11-
kind: SriovResourceFilter
12-
listKind: SriovResourceFilterList
13-
plural: sriovresourcefilters
14-
singular: sriovresourcefilter
11+
kind: SriovResourcePolicy
12+
listKind: SriovResourcePolicyList
13+
plural: sriovresourcepolicies
14+
singular: sriovresourcepolicy
1515
scope: Namespaced
1616
versions:
1717
- name: v1alpha1
1818
schema:
1919
openAPIV3Schema:
20-
description: SriovResourceFilter is a filter for SR-IOV resources
20+
description: SriovResourcePolicy defines a policy for advertising SR-IOV devices
21+
as Kubernetes resources
2122
properties:
2223
apiVersion:
2324
description: |-
@@ -37,7 +38,7 @@ spec:
3738
metadata:
3839
type: object
3940
spec:
40-
description: SriovResourceFilterSpec is the spec for a SriovResourceFilter
41+
description: SriovResourcePolicySpec is the spec for a SriovResourcePolicy
4142
properties:
4243
configs:
4344
items:

pkg/api/sriovdra/v1alpha1/api.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ import (
2222

2323
//nolint:gochecknoinits // Required for Kubernetes scheme registration
2424
func init() {
25-
SchemeBuilder.Register(&SriovResourceFilter{}, &SriovResourceFilterList{})
25+
SchemeBuilder.Register(&SriovResourcePolicy{}, &SriovResourcePolicyList{})
2626
}
2727

2828
// +genclient
2929
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3030

31-
// SriovResourceFilter is a filter for SR-IOV resources
32-
type SriovResourceFilter struct {
31+
// SriovResourcePolicy defines a policy for advertising SR-IOV devices as Kubernetes resources
32+
type SriovResourcePolicy struct {
3333
metav1.TypeMeta `json:",inline"`
3434
metav1.ObjectMeta `json:"metadata,omitempty"`
35-
Spec SriovResourceFilterSpec `json:"spec"`
35+
Spec SriovResourcePolicySpec `json:"spec"`
3636
}
3737

38-
// SriovResourceFilterSpec is the spec for a SriovResourceFilter
39-
type SriovResourceFilterSpec struct {
38+
// SriovResourcePolicySpec is the spec for a SriovResourcePolicy
39+
type SriovResourcePolicySpec struct {
4040
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
4141
Configs []Config `json:"configs,omitempty"`
4242
}
@@ -60,9 +60,9 @@ type ResourceFilter struct {
6060
// +genclient
6161
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6262

63-
// SriovResourceFilterList contains a list of SriovResourceFilter
64-
type SriovResourceFilterList struct {
63+
// SriovResourcePolicyList contains a list of SriovResourcePolicy
64+
type SriovResourcePolicyList struct {
6565
metav1.TypeMeta `json:",inline"`
6666
metav1.ListMeta `json:"metadata,omitempty"`
67-
Items []SriovResourceFilter `json:"items"`
67+
Items []SriovResourcePolicy `json:"items"`
6868
}

pkg/api/sriovdra/v1alpha1/zz_generated.deepcopy.go

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)