Skip to content

Commit

Permalink
Validate spec.NumVfs equal to real numVfs for externally managed
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Guerrero <[email protected]>
  • Loading branch information
mlguerrero12 committed Nov 7, 2023
1 parent 33a4ca2 commit e3a9f04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func validatePolicyForNodeState(policy *sriovnetworkv1.SriovNetworkNodePolicy, s

// Externally create validations
if policy.Spec.ExternallyManaged {
if policy.Spec.NumVfs > iface.NumVfs {
return nil, fmt.Errorf("numVfs(%d) in CR %s is higher than the virtual functions allocated for the PF externally value(%d)", policy.Spec.NumVfs, policy.GetName(), iface.NumVfs)
if policy.Spec.NumVfs != iface.NumVfs {
return nil, fmt.Errorf("numVfs(%d) in CR %s is different than the virtual functions allocated for the PF externally value(%d)", policy.Spec.NumVfs, policy.GetName(), iface.NumVfs)
}

if policy.Spec.Mtu != 0 && policy.Spec.Mtu > iface.Mtu {
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func TestValidatePolicyForNodeStateWithInvalidNumVfsExternallyCreated(t *testing
}
g := NewGomegaWithT(t)
_, err := validatePolicyForNodeState(policy, state, NewNode())
g.Expect(err).To(MatchError(ContainSubstring(fmt.Sprintf("numVfs(%d) in CR %s is higher than the virtual functions allocated for the PF externally value(%d)", policy.Spec.NumVfs, policy.GetName(), state.Status.Interfaces[0].NumVfs))))
g.Expect(err).To(MatchError(ContainSubstring(fmt.Sprintf("numVfs(%d) in CR %s is different than the virtual functions allocated for the PF externally value(%d)", policy.Spec.NumVfs, policy.GetName(), state.Status.Interfaces[0].NumVfs))))
}

func TestValidatePolicyForNodeStateWithValidNumVfsExternallyCreated(t *testing.T) {
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestValidatePolicyForNodeStateWithValidLowerNumVfsExternallyCreated(t *test
}
g := NewGomegaWithT(t)
_, err := validatePolicyForNodeState(policy, state, NewNode())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(err).To(MatchError(ContainSubstring(fmt.Sprintf("numVfs(%d) in CR %s is different than the virtual functions allocated for the PF externally value(%d)", policy.Spec.NumVfs, policy.GetName(), state.Status.Interfaces[0].NumVfs))))
}

func TestValidatePolicyForNodePolicyWithOutExternallyManageConflict(t *testing.T) {
Expand Down

0 comments on commit e3a9f04

Please sign in to comment.