Skip to content

Commit

Permalink
Bug 2029867: backport for allowing netFilter to be set alone in NicSe…
Browse files Browse the repository at this point in the history
…lector

Backport of
k8snetworkplumbingwg/sriov-network-operator#210.

In `staticValidateSriovNetworkNodePolicy`, we now allow a NicSelector to
only have NetFilter defined.

This will be useful for the OpenStack platform, where we can request a
Network Node Policy only by its Network ID.
  • Loading branch information
EmilienM committed Dec 8, 2021
1 parent 733f15a commit 120d3ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/golang/glog"
"k8s.io/api/admission/v1"
v1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

Expand Down Expand Up @@ -89,8 +89,8 @@ func staticValidateSriovNetworkNodePolicy(cr *sriovnetworkv1.SriovNetworkNodePol
return false, fmt.Errorf("resource name \"%s\" contains invalid characters, the accepted syntax of the regular expressions is: \"^[a-zA-Z0-9_]+$\"", cr.Spec.ResourceName)
}

if cr.Spec.NicSelector.Vendor == "" && cr.Spec.NicSelector.DeviceID == "" && len(cr.Spec.NicSelector.PfNames) == 0 && len(cr.Spec.NicSelector.RootDevices) == 0 {
return false, fmt.Errorf("at least one of these parameters (vendor, deviceID, pfNames or rootDevices) has to be defined in nicSelector in CR %s", cr.GetName())
if cr.Spec.NicSelector.Vendor == "" && cr.Spec.NicSelector.DeviceID == "" && len(cr.Spec.NicSelector.PfNames) == 0 && len(cr.Spec.NicSelector.RootDevices) == 0 && cr.Spec.NicSelector.NetFilter == "" {
return false, fmt.Errorf("at least one of these parameters (vendor, deviceID, pfNames, rootDevices or netFilter) has to be defined in nicSelector in CR %s", cr.GetName())
}

if cr.Spec.NicSelector.Vendor != "" {
Expand Down
24 changes: 24 additions & 0 deletions pkg/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,27 @@ func TestStaticValidateSriovNetworkNodePolicyWithInvalidNicSelector(t *testing.T
g.Expect(err).To(HaveOccurred())
g.Expect(ok).To(Equal(false))
}

func TestValidatePolicyForNodeStateWithValidNetFilter(t *testing.T) {
interfaceSelected = false
state := newNodeState()
policy := &SriovNetworkNodePolicy{
Spec: SriovNetworkNodePolicySpec{
DeviceType: "netdevice",
NicSelector: SriovNetworkNicSelector{
NetFilter: "openstack/NetworkID:ada9ec67-2c97-467c-b674-c47200e2f5da",
},
NodeSelector: map[string]string{
"feature.node.kubernetes.io/network-sriov.capable": "true",
},
NumVfs: 63,
Priority: 99,
ResourceName: "p0",
},
}
g := NewGomegaWithT(t)
ok, err := validatePolicyForNodeState(policy, state)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ok).To(Equal(true))
g.Expect(interfaceSelected).To(Equal(true))
}

0 comments on commit 120d3ff

Please sign in to comment.