Skip to content

Commit a8da5d9

Browse files
committed
Add DpuNetwork CRD and controller
Introduce DpuNetwork custom resource and reconciler: maintains dpu-device-plugin-config ConfigMap and NADs per network, with finalizer cleanup on delete. Includes RBAC, examples and test. Signed-off-by: Alkama Hasan <alkamah@marvell.com>
1 parent 1ab76b5 commit a8da5d9

19 files changed

Lines changed: 1702 additions & 142 deletions

File tree

api/v1/dpunetwork_types.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// DpuNetworkSpec defines the desired state of DpuNetwork.
24+
type DpuNetworkSpec struct {
25+
// NodeSelector specifies which nodes this DpuNetwork should apply to.
26+
// If empty, the DpuNetwork will apply to all nodes.
27+
// +optional
28+
NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
29+
30+
// DpuSelector specifies which DPUs (and their VFs) this DpuNetwork targets.
31+
//
32+
// Note: Today this is treated as an opaque selector definition; the controller
33+
// parses vfId ranges from matchExpressions (if present) but does not yet
34+
// validate against a per-VF inventory.
35+
// +optional
36+
DpuSelector *metav1.LabelSelector `json:"dpuSelector,omitempty"`
37+
38+
// IsAccelerated indicates whether the network should be treated as accelerated
39+
// by downstream components.
40+
// +optional
41+
IsAccelerated bool `json:"isAccelerated,omitempty"`
42+
}
43+
44+
// DpuNetworkStatus defines the observed state of DpuNetwork.
45+
type DpuNetworkStatus struct {
46+
// Conditions is the status of the DpuNetwork.
47+
// +optional
48+
Conditions []metav1.Condition `json:"conditions,omitempty"`
49+
50+
// ResourceName is the Kubernetes extended resource name generated for this network.
51+
// +optional
52+
ResourceName string `json:"resourceName,omitempty"`
53+
54+
// SelectedVFs is the list of VF IDs parsed from vfId ranges.
55+
// +optional
56+
SelectedVFs []int32 `json:"selectedVFs,omitempty"`
57+
}
58+
59+
//+kubebuilder:object:root=true
60+
//+kubebuilder:subresource:status
61+
//+kubebuilder:resource:scope=Cluster,shortName=dpunet
62+
//+kubebuilder:printcolumn:name="Resource",type="string",JSONPath=".status.resourceName"
63+
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
64+
65+
// DpuNetwork is the Schema for the dpunetworks API.
66+
type DpuNetwork struct {
67+
metav1.TypeMeta `json:",inline"`
68+
metav1.ObjectMeta `json:"metadata,omitempty"`
69+
70+
Spec DpuNetworkSpec `json:"spec,omitempty"`
71+
Status DpuNetworkStatus `json:"status,omitempty"`
72+
}
73+
74+
//+kubebuilder:object:root=true
75+
76+
// DpuNetworkList contains a list of DpuNetwork.
77+
type DpuNetworkList struct {
78+
metav1.TypeMeta `json:",inline"`
79+
metav1.ListMeta `json:"metadata,omitempty"`
80+
Items []DpuNetwork `json:"items"`
81+
}
82+
83+
func init() {
84+
SchemeBuilder.Register(&DpuNetwork{}, &DpuNetworkList{})
85+
}

api/v1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func main() {
133133
setupLog.Error(err, "unable to create controller", "controller", "DataProcessingUnit")
134134
os.Exit(1)
135135
}
136+
if err := (&controller.DpuNetworkReconciler{
137+
Client: mgr.GetClient(),
138+
Scheme: mgr.GetScheme(),
139+
}).SetupWithManager(mgr); err != nil {
140+
setupLog.Error(err, "unable to create controller", "controller", "DpuNetwork")
141+
os.Exit(1)
142+
}
136143
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
137144
if err = (&configv1.DpuOperatorConfig{}).SetupWebhookWithManager(mgr); err != nil {
138145
setupLog.Error(err, "unable to create webhook", "webhook", "DpuOperatorConfig")

0 commit comments

Comments
 (0)