Skip to content

Commit

Permalink
Merge pull request #660 from mlguerrero12/netdevicedefaultapi
Browse files Browse the repository at this point in the history
Set netdevice as default in the CRD
  • Loading branch information
zeeke authored Mar 19, 2024
2 parents e94dc27 + 396f122 commit a496b72
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions api/v1/sriovnetworknodepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type SriovNetworkNodePolicySpec struct {
// NicSelector selects the NICs to be configured
NicSelector SriovNetworkNicSelector `json:"nicSelector"`
// +kubebuilder:validation:Enum=netdevice;vfio-pci
// +kubebuilder:default=netdevice
// The driver type for configured VFs. Allowed value "netdevice", "vfio-pci". Defaults to netdevice.
DeviceType string `json:"deviceType,omitempty"`
// RDMA mode. Defaults to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ spec:
description: SriovNetworkNodePolicySpec defines the desired state of SriovNetworkNodePolicy
properties:
deviceType:
default: netdevice
description: The driver type for configured VFs. Allowed value "netdevice",
"vfio-pci". Defaults to netdevice.
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ spec:
description: SriovNetworkNodePolicySpec defines the desired state of SriovNetworkNodePolicy
properties:
deviceType:
default: netdevice
description: The driver type for configured VFs. Allowed value "netdevice",
"vfio-pci". Defaults to netdevice.
enum:
Expand Down
11 changes: 3 additions & 8 deletions pkg/webhook/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
)

var (
defaultPriorityPatch = map[string]interface{}{"op": "add", "path": "/spec/priority", "value": 99}
defaultDeviceTypePatch = map[string]interface{}{"op": "add", "path": "/spec/deviceType", "value": "netdevice"}
defaultIsRdmaPatch = map[string]interface{}{"op": "add", "path": "/spec/isRdma", "value": false}
InfiniBandIsRdmaPatch = map[string]interface{}{"op": "add", "path": "/spec/isRdma", "value": true}
defaultPriorityPatch = map[string]interface{}{"op": "add", "path": "/spec/priority", "value": 99}
defaultIsRdmaPatch = map[string]interface{}{"op": "add", "path": "/spec/isRdma", "value": false}
InfiniBandIsRdmaPatch = map[string]interface{}{"op": "add", "path": "/spec/isRdma", "value": true}
)

func mutateSriovNetworkNodePolicy(cr map[string]interface{}) (*v1.AdmissionResponse, error) {
Expand All @@ -36,10 +35,6 @@ func mutateSriovNetworkNodePolicy(cr map[string]interface{}) (*v1.AdmissionRespo
log.Log.V(2).Info("mutateSriovNetworkNodePolicy(): set default priority to lowest for", "policy-name", name)
patchs = append(patchs, defaultPriorityPatch)
}
if _, ok := spec.(map[string]interface{})["deviceType"]; !ok {
log.Log.V(2).Info("mutateSriovNetworkNodePolicy(): set default deviceType to netdevice for policy", "policy-name", name)
patchs = append(patchs, defaultDeviceTypePatch)
}
if _, ok := spec.(map[string]interface{})["isRdma"]; !ok {
log.Log.V(2).Info("mutateSriovNetworkNodePolicy(): set default isRdma to false for policy", "policy-name", name)
patchs = append(patchs, defaultIsRdmaPatch)
Expand Down

0 comments on commit a496b72

Please sign in to comment.