Skip to content

Commit

Permalink
Set netdevice as default in the CRD
Browse files Browse the repository at this point in the history
This sets netdevice as default in the CRD to not depend
on the mutating webhook.

Fixes k8snetworkplumbingwg/sriov-network-operator#632

Signed-off-by: Marcelo Guerrero <[email protected]>
  • Loading branch information
mlguerrero12 committed Mar 18, 2024
1 parent 82a6d6f commit 396f122
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 396f122

Please sign in to comment.