From e3a9f04fb5390d49139fbec6c8b55f89ffa31a01 Mon Sep 17 00:00:00 2001 From: Marcelo Guerrero Date: Tue, 7 Nov 2023 10:10:40 +0100 Subject: [PATCH] Validate spec.NumVfs equal to real numVfs for externally managed Signed-off-by: Marcelo Guerrero --- pkg/webhook/validate.go | 4 ++-- pkg/webhook/validate_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/webhook/validate.go b/pkg/webhook/validate.go index 366881dc67..1a3eeae8d6 100644 --- a/pkg/webhook/validate.go +++ b/pkg/webhook/validate.go @@ -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 { diff --git a/pkg/webhook/validate_test.go b/pkg/webhook/validate_test.go index 990886906b..596623356d 100644 --- a/pkg/webhook/validate_test.go +++ b/pkg/webhook/validate_test.go @@ -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) { @@ -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) {