From 1c3eec7cc377eb120cba43a4b75adcd4407bb6ce Mon Sep 17 00:00:00 2001 From: cyclinder Date: Tue, 24 Sep 2024 17:10:56 +0800 Subject: [PATCH] Fix wrong validate podMACPrefix when creating spiderMultusConfig Signed-off-by: cyclinder --- .../coordinator_validate.go | 8 +---- test/doc/spidermultus.md | 3 ++ test/e2e/spidermultus/spidermultus_test.go | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/pkg/coordinatormanager/coordinator_validate.go b/pkg/coordinatormanager/coordinator_validate.go index 486137874..299039726 100644 --- a/pkg/coordinatormanager/coordinator_validate.go +++ b/pkg/coordinatormanager/coordinator_validate.go @@ -155,12 +155,6 @@ func validateCoordinatorPodMACPrefix(prefix *string) *field.Error { return errInvalid } - // the lowest bit of first byte must be 0 - // example: 0*:** - if string(parts[0][0]) != "0" { - return field.Invalid(podMACPrefixField, *prefix, "the lowest bit of the first byte must be 0") - } - fb, err := strconv.ParseInt(parts[0], 16, 0) if err != nil { return errInvalid @@ -172,7 +166,7 @@ func validateCoordinatorPodMACPrefix(prefix *string) *field.Error { bb := fmt.Sprintf("%08b", fb) if string(bb[7]) != "0" { - return field.Invalid(podMACPrefixField, *prefix, "not a unicast MAC") + return field.Invalid(podMACPrefixField, *prefix, "not a unicast MAC: the lowest bit of the first byte must be 0") } return nil diff --git a/test/doc/spidermultus.md b/test/doc/spidermultus.md index e00b4b3e5..2bbdb840d 100644 --- a/test/doc/spidermultus.md +++ b/test/doc/spidermultus.md @@ -25,3 +25,6 @@ | M00021 | create a spidermultusconfig and pod to verify chainCNI json config if works | p3 | | done | | | M00022 | test podRPFilter and hostRPFilter in spidermultusconfig | p3 | | done | | M00023 | set hostRPFilter and podRPFilter to a invalid value | p3 | | done | +| M00024 | verify the podMACPrefix filed | p3 | | done | | + + diff --git a/test/e2e/spidermultus/spidermultus_test.go b/test/e2e/spidermultus/spidermultus_test.go index 5fa35e648..205b57325 100644 --- a/test/e2e/spidermultus/spidermultus_test.go +++ b/test/e2e/spidermultus/spidermultus_test.go @@ -829,4 +829,37 @@ var _ = Describe("test spidermultus", Label("SpiderMultusConfig"), func() { Expect(string(data)).To(Equal("4096\n"), "net.core.somaxconn: %s", data) }) + It("verify the podMACPrefix filed", Label("M00024"), func() { + smcName := "test-multus-" + common.GenerateString(10, true) + smc := &spiderpoolv2beta1.SpiderMultusConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: smcName, + Namespace: namespace, + }, + Spec: spiderpoolv2beta1.MultusCNIConfigSpec{ + EnableCoordinator: ptr.To(true), + CoordinatorConfig: &spiderpoolv2beta1.CoordinatorSpec{ + PodMACPrefix: ptr.To("9e:10"), + }, + }, + } + err := frame.CreateSpiderMultusInstance(smc) + Expect(err).NotTo(HaveOccurred()) + + tmpName := "test-multus-" + common.GenerateString(10, true) + invalid := &spiderpoolv2beta1.SpiderMultusConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: tmpName, + Namespace: namespace, + }, + Spec: spiderpoolv2beta1.MultusCNIConfigSpec{ + EnableCoordinator: ptr.To(true), + CoordinatorConfig: &spiderpoolv2beta1.CoordinatorSpec{ + PodMACPrefix: ptr.To("01:10"), + }, + }, + } + err = frame.CreateSpiderMultusInstance(invalid) + Expect(err).To(HaveOccurred()) + }) })