Repository: spidernet-io/spiderpool
Pull request #1340 (2023-02-20 03:45:21)

fix: Concurrently created deployments of the same name causing check events to fail.
**make sure your commit is signed off**
Signed-off-by: ty-dc <tao.yang@daocloud.io>


Patch:
diff --git a/charts/spiderpool/crds/spiderpool.spidernet.io_spidersubnets.yaml b/charts/spiderpool/crds/spiderpool.spidernet.io_spidersubnets.yaml
index 68de22682..5690d9ae5 100644
--- a/charts/spiderpool/crds/spiderpool.spidernet.io_spidersubnets.yaml
+++ b/charts/spiderpool/crds/spiderpool.spidernet.io_spidersubnets.yaml
@@ -71,6 +71,7 @@ spec:
               ips:
                 items:
                   type: string
+                minItems: 1
                 type: array
               routes:
                 items:
@@ -93,6 +94,7 @@ spec:
                 minimum: 0
                 type: integer
             required:
+            - ips
             - subnet
             type: object
           status:
diff --git a/pkg/constant/k8s.go b/pkg/constant/k8s.go
index 2b6ddc3a5..52aa32e65 100644
--- a/pkg/constant/k8s.go
+++ b/pkg/constant/k8s.go
@@ -72,13 +72,10 @@ const (
 	LabelIPPoolOwnerApplication    = AnnotationPre + "/owner-application"
 	LabelIPPoolOwnerApplicationUID = AnnotationPre + "/owner-application-uid"
 	LabelIPPoolVersion             = AnnotationPre + "/ippool-version"
-	LabelIPPoolVersionV4           = "IPv4"
-	LabelIPPoolVersionV6           = "IPv6"
 	LabelIPPoolReclaimIPPool       = AnnoSpiderSubnetReclaimIPPool
 	LabelIPPoolInterface           = AnnotationPre + "/interface"
-
-	LabelSubnetCIDR = AnnotationPre + "/subnet-cidr"
-	LabelIPPoolCIDR = AnnotationPre + "/ippool-cidr"
+	LabelIPPoolVersionV4           = "IPv4"
+	LabelIPPoolVersionV6           = "IPv6"
 )
 
 const (
diff --git a/pkg/ip/utils.go b/pkg/ip/utils.go
index 773d1a30a..9bb659a04 100644
--- a/pkg/ip/utils.go
+++ b/pkg/ip/utils.go
@@ -5,7 +5,6 @@ package ip
 
 import (
 	"net"
-	"strings"
 
 	"github.com/spidernet-io/spiderpool/pkg/types"
 )
@@ -23,15 +22,3 @@ func AssembleTotalIPs(ipVersion types.IPVersion, ipRanges, excludedIPRanges []st
 
 	return totalIPs, nil
 }
-
-func CIDRToLabelValue(ipVersion types.IPVersion, subnet string) (string, error) {
-	if err := IsCIDR(ipVersion, subnet); err != nil {
-		return "", err
-	}
-
-	value := strings.Replace(subnet, ".", "-", 3)
-	value = strings.Replace(value, ":", "-", 7)
-	value = strings.Replace(value, "/", "-", 1)
-
-	return value, nil
-}
diff --git a/pkg/ippoolmanager/ippool_mutate.go b/pkg/ippoolmanager/ippool_mutate.go
index a12325d4e..a2cc2a71b 100644
--- a/pkg/ippoolmanager/ippool_mutate.go
+++ b/pkg/ippoolmanager/ippool_mutate.go
@@ -5,12 +5,12 @@ package ippoolmanager
 
 import (
 	"context"
+	"errors"
 	"fmt"
 
 	apierrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	ctrl "sigs.k8s.io/controller-runtime"
-	"sigs.k8s.io/controller-runtime/pkg/client"
 	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 
 	"github.com/spidernet-io/spiderpool/pkg/constant"
@@ -29,6 +29,12 @@ func (iw *IPPoolWebhook) mutateIPPool(ctx context.Context, ipPool *spiderpoolv1.
 		return nil
 	}
 
+	if iw.EnableSpiderSubnet {
+		if err := iw.setControllerSubnet(ctx, ipPool); err != nil {
+			return apierrors.NewInternalError(fmt.Errorf("failed to set the reference of the controller Subnet: %v", err))
+		}
+	}
+
 	if !controllerutil.ContainsFinalizer(ipPool, constant.SpiderFinalizer) {
 		controllerutil.AddFinalizer(ipPool, constant.SpiderFinalizer)
 		logger.Sugar().Infof("Add finalizer %s", constant.SpiderFinalizer)
@@ -41,7 +47,7 @@ func (iw *IPPoolWebhook) mutateIPPool(ctx context.Context, ipPool *spiderpoolv1.
 		} else if spiderpoolip.IsIPv6CIDR(ipPool.Spec.Subnet) {
 			version = constant.IPv6
 		} else {
-			return fmt.Errorf("failed to generate 'spec.ipVersion' from 'spec.subnet' %s, nothing to mutate", ipPool.Spec.Subnet)
+			return errors.New("invalid 'spec.ipVersion', noting to mutate")
 		}
 
 		ipPool.Spec.IPVersion = new(types.IPVersion)
@@ -49,25 +55,6 @@ func (iw *IPPoolWebhook) mutateIPPool(ctx context.Context, ipPool *spiderpoolv1.
 		logger.Sugar().Infof("Set 'spec.ipVersion' to %d", version)
 	}
 
-	cidr, err := spiderpoolip.CIDRToLabelValue(*ipPool.Spec.IPVersion, ipPool.Spec.Subnet)
-	if err != nil {
-		return fmt.Errorf("failed to parse 'spec.subnet' %s as a valid label value: %v", ipPool.Spec.Subnet, err)
-	}
-
-	if v, ok := ipPool.Labels[constant.LabelIPPoolCIDR]; !ok || v != cidr {
-		if ipPool.Labels == nil {
-			ipPool.Labels = make(map[string]string)
-		}
-		ipPool.Labels[constant.LabelIPPoolCIDR] = cidr
-		logger.Sugar().Infof("Set label %s: %s", constant.LabelIPPoolCIDR, cidr)
-	}
-
-	if iw.EnableSpiderSubnet {
-		if err := iw.setControllerSubnet(ctx, ipPool); err != nil {
-			return apierrors.NewInternalError(fmt.Errorf("failed to set the reference of the controller Subnet: %v", err))
-		}
-	}
-
 	if len(ipPool.Spec.IPs) > 1 {
 		mergedIPs, err := spiderpoolip.MergeIPRanges(*ipPool.Spec.IPVersion, ipPool.Spec.IPs)
 		if err != nil {
@@ -100,35 +87,29 @@ func (iw *IPPoolWebhook) setControllerSubnet(ctx context.Context, ipPool *spider
 		return nil
 	}
 
-	cidr, err := spiderpoolip.CIDRToLabelValue(*ipPool.Spec.IPVersion, ipPool.Spec.Subnet)
-	if err != nil {
-		return fmt.Errorf("failed to parse CIDR %s as a valid label value: %v", ipPool.Spec.Subnet, err)
-	}
-
 	var subnetList spiderpoolv1.SpiderSubnetList
-	if err := iw.Client.List(
-		ctx,
-		&subnetList,
-		client.MatchingLabels{constant.LabelSubnetCIDR: cidr},
-	); err != nil {
+	if err := iw.Client.List(ctx, &subnetList); err != nil {
 		return fmt.Errorf("failed to list Subnets: %v", err)
 	}
 
-	if len(subnetList.Items) == 0 {
-		return nil
-	}
-
-	subnet := subnetList.Items[0]
-	if !metav1.IsControlledBy(ipPool, &subnet) {
-		if err := ctrl.SetControllerReference(&subnet, ipPool, iw.Scheme); err != nil {
-			return fmt.Errorf("failed to set owner reference: %v", err)
+	for _, subnet := range subnetList.Items {
+		if subnet.Spec.Subnet == ipPool.Spec.Subnet {
+			if !metav1.IsControlledBy(ipPool, &subnet) {
+				if err := ctrl.SetControllerReference(&subnet, ipPool, iw.Scheme); err != nil {
+					return fmt.Errorf("failed to set owner reference: %v", err)
+				}
+				logger.Sugar().Infof("Set owner reference as Subnet %s", subnet.Name)
+			}
+
+			if ipPool.Labels == nil {
+				ipPool.Labels = make(map[string]string)
+			}
+			if v, ok := ipPool.Labels[constant.LabelIPPoolOwnerSpiderSubnet]; !ok || v != subnet.Name {
+				ipPool.Labels[constant.LabelIPPoolOwnerSpiderSubnet] = subnet.Name
+				logger.Sugar().Infof("Set label %s: %s", constant.LabelIPPoolOwnerSpiderSubnet, subnet.Name)
+			}
+			break
 		}
-		logger.Sugar().Infof("Set owner reference as Subnet %s", subnet.Name)
-	}
-
-	if v, ok := ipPool.Labels[constant.LabelIPPoolOwnerSpiderSubnet]; !ok || v != subnet.Name {
-		ipPool.Labels[constant.LabelIPPoolOwnerSpiderSubnet] = subnet.Name
-		logger.Sugar().Infof("Set label %s: %s", constant.LabelIPPoolOwnerSpiderSubnet, subnet.Name)
 	}
 
 	return nil
diff --git a/pkg/ippoolmanager/ippool_subnet_validate.go b/pkg/ippoolmanager/ippool_subnet_validate.go
index 5c661d0e4..424bf18a5 100644
--- a/pkg/ippoolmanager/ippool_subnet_validate.go
+++ b/pkg/ippoolmanager/ippool_subnet_validate.go
@@ -66,6 +66,10 @@ func (iw *IPPoolWebhook) validateSubnetControllerExist(ctx context.Context, ipPo
 		return nil, field.InternalError(subnetField, fmt.Errorf("failed to get controller Subnet %s: %v", owner.Name, err))
 	}
 
+	if subnet.Spec.Subnet != ipPool.Spec.Subnet {
+		return nil, field.InternalError(subnetField, fmt.Errorf("invalid controller Subnet %s with different 'spec.subnet' %s", owner.Name, subnet.Spec.Subnet))
+	}
+
 	if subnet.DeletionTimestamp != nil {
 		return nil, field.Forbidden(
 			subnetField,
diff --git a/pkg/ippoolmanager/ippool_validate.go b/pkg/ippoolmanager/ippool_validate.go
index 084322efa..df6624781 100644
--- a/pkg/ippoolmanager/ippool_validate.go
+++ b/pkg/ippoolmanager/ippool_validate.go
@@ -9,7 +9,6 @@ import (
 	"strconv"
 
 	"k8s.io/apimachinery/pkg/util/validation/field"
-	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	"github.com/spidernet-io/spiderpool/pkg/constant"
 	spiderpoolip "github.com/spidernet-io/spiderpool/pkg/ip"
@@ -31,7 +30,7 @@ func (iw *IPPoolWebhook) validateCreateIPPool(ctx context.Context, ipPool *spide
 		return field.ErrorList{err}
 	}
 
-	if err := iw.validateIPPoolCIDR(ctx, ipPool); err != nil {
+	if err := iw.validateIPPoolSubnet(ctx, ipPool); err != nil {
 		return field.ErrorList{err}
 	}
 
@@ -161,7 +160,7 @@ func (iw *IPPoolWebhook) validateIPPoolIPVersion(version *types.IPVersion) *fiel
 	return nil
 }
 
-func (iw *IPPoolWebhook) validateIPPoolCIDR(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) *field.Error {
+func (iw *IPPoolWebhook) validateIPPoolSubnet(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) *field.Error {
 	if err := spiderpoolip.IsCIDR(*ipPool.Spec.IPVersion, ipPool.Spec.Subnet); err != nil {
 		return field.Invalid(
 			subnetField,
@@ -170,11 +169,6 @@ func (iw *IPPoolWebhook) validateIPPoolCIDR(ctx context.Context, ipPool *spiderp
 		)
 	}
 
-	if iw.EnableSpiderSubnet {
-		return nil
-	}
-
-	// TODO(iiiceoo): Use label selector.
 	var ipPoolList spiderpoolv1.SpiderIPPoolList
 	if err := iw.Client.List(ctx, &ipPoolList); err != nil {
 		return field.InternalError(subnetField, fmt.Errorf("failed to list IPPools: %v", err))
@@ -216,18 +210,8 @@ func (iw *IPPoolWebhook) validateIPPoolAvailableIPs(ctx context.Context, ipPool
 		return err
 	}
 
-	cidr, err := spiderpoolip.CIDRToLabelValue(*ipPool.Spec.IPVersion, ipPool.Spec.Subnet)
-	if err != nil {
-		return field.InternalError(ipsField, fmt.Errorf("failed to parse CIDR %s as a valid label value: %v", ipPool.Spec.Subnet, err))
-	}
-
-	// TODO(iiiceoo): The list in validateIPPoolCIDR should be reused.
 	var ipPoolList spiderpoolv1.SpiderIPPoolList
-	if err := iw.Client.List(
-		ctx,
-		&ipPoolList,
-		client.MatchingLabels{constant.LabelIPPoolCIDR: cidr},
-	); err != nil {
+	if err := iw.Client.List(ctx, &ipPoolList); err != nil {
 		return field.InternalError(ipsField, fmt.Errorf("failed to list IPPools: %v", err))
 	}
 
@@ -237,7 +221,7 @@ func (iw *IPPoolWebhook) validateIPPoolAvailableIPs(ctx context.Context, ipPool
 	}
 
 	for _, pool := range ipPoolList.Items {
-		if pool.Name != ipPool.Name {
+		if pool.Spec.Subnet == ipPool.Spec.Subnet && pool.Name != ipPool.Name {
 			existIPs, err := spiderpoolip.AssembleTotalIPs(*pool.Spec.IPVersion, pool.Spec.IPs, pool.Spec.ExcludeIPs)
 			if err != nil {
 				return field.InternalError(ipsField, fmt.Errorf("failed to assemble the total IP addresses of the existing IPPool %s: %v", pool.Name, err))
@@ -258,6 +242,17 @@ func (iw *IPPoolWebhook) validateIPPoolAvailableIPs(ctx context.Context, ipPool
 }
 
 func (iw *IPPoolWebhook) validateIPPoolIPs(version types.IPVersion, subnet string, ips []string) *field.Error {
+	if len(ips) == 0 {
+		if iw.EnableSpiderSubnet {
+			return nil
+		}
+
+		return field.Required(
+			ipsField,
+			"requires at least one item",
+		)
+	}
+
 	for i, r := range ips {
 		if err := ValidateContainsIPRange(ipsField.Index(i), version, subnet, r); err != nil {
 			return err
diff --git a/pkg/k8s/apis/spiderpool.spidernet.io/v1/spidersubnet_types.go b/pkg/k8s/apis/spiderpool.spidernet.io/v1/spidersubnet_types.go
index d96403acb..035000e76 100644
--- a/pkg/k8s/apis/spiderpool.spidernet.io/v1/spidersubnet_types.go
+++ b/pkg/k8s/apis/spiderpool.spidernet.io/v1/spidersubnet_types.go
@@ -16,7 +16,8 @@ type SubnetSpec struct {
 	// +kubebuilder:validation:Required
 	Subnet string `json:"subnet"`
 
-	// +kubebuilder:validation:Optional
+	// +kubebuilder:validation:MinItems=1
+	// +kubebuilder:validation:Required
 	IPs []string `json:"ips"`
 
 	// +kubebuilder:validation:Optional
diff --git a/pkg/reservedipmanager/reservedip_mutate.go b/pkg/reservedipmanager/reservedip_mutate.go
index cc59435bf..363010575 100644
--- a/pkg/reservedipmanager/reservedip_mutate.go
+++ b/pkg/reservedipmanager/reservedip_mutate.go
@@ -35,7 +35,7 @@ func (rw *ReservedIPWebhook) mutateReservedIP(ctx context.Context, rIP *spiderpo
 		} else if spiderpoolip.IsIPv6IPRange(rIP.Spec.IPs[0]) {
 			version = constant.IPv6
 		} else {
-			return fmt.Errorf("failed to generate 'spec.ipVersion' from 'spec.ips[0]' %s, nothing to mutate", rIP.Spec.IPs[0])
+			return errors.New("invalid 'spec.ipVersion', noting to mutate")
 		}
 
 		rIP.Spec.IPVersion = new(types.IPVersion)
diff --git a/pkg/reservedipmanager/reservedip_validate.go b/pkg/reservedipmanager/reservedip_validate.go
index 6ba4e5e19..f046f0777 100644
--- a/pkg/reservedipmanager/reservedip_validate.go
+++ b/pkg/reservedipmanager/reservedip_validate.go
@@ -5,6 +5,7 @@ package reservedipmanager
 
 import (
 	"context"
+	"fmt"
 	"strconv"
 
 	"k8s.io/apimachinery/pkg/util/validation/field"
@@ -71,7 +72,7 @@ func validateReservedIPShouldNotBeChanged(oldRIP, newRIP *spiderpoolv1.SpiderRes
 }
 
 func (rw *ReservedIPWebhook) validateReservedIPSpec(ctx context.Context, rIP *spiderpoolv1.SpiderReservedIP) *field.Error {
-	return rw.validateReservedIPs(ctx, *rIP.Spec.IPVersion, rIP.Spec.IPs)
+	return rw.validateReservedIPAvailableIP(ctx, *rIP.Spec.IPVersion, rIP)
 }
 
 func (rw *ReservedIPWebhook) validateReservedIPIPVersion(version *types.IPVersion) *field.Error {
@@ -111,13 +112,38 @@ func (rw *ReservedIPWebhook) validateReservedIPIPVersion(version *types.IPVersio
 	return nil
 }
 
-func (rw *ReservedIPWebhook) validateReservedIPs(ctx context.Context, version types.IPVersion, ips []string) *field.Error {
-	for i, r := range ips {
-		if err := spiderpoolip.IsIPRange(version, r); err != nil {
-			return field.Invalid(
-				ipsField.Index(i),
-				ips[i],
-				err.Error(),
+func (rw *ReservedIPWebhook) validateReservedIPAvailableIP(ctx context.Context, version types.IPVersion, rIP *spiderpoolv1.SpiderReservedIP) *field.Error {
+	if len(rIP.Spec.IPs) == 0 {
+		return nil
+	}
+
+	newReservedIPs, err := spiderpoolip.ParseIPRanges(version, rIP.Spec.IPs)
+	if err != nil {
+		return field.Invalid(
+			ipsField,
+			rIP.Spec.IPs,
+			err.Error(),
+		)
+	}
+
+	var rIPList spiderpoolv1.SpiderReservedIPList
+	if err := rw.List(ctx, &rIPList); err != nil {
+		return field.InternalError(ipsField, fmt.Errorf("failed to list ReservedIPs: %v", err))
+	}
+
+	for _, r := range rIPList.Items {
+		if r.Name == rIP.Name || *r.Spec.IPVersion != version {
+			continue
+		}
+
+		existReservedIPs, err := spiderpoolip.ParseIPRanges(version, r.Spec.IPs)
+		if err != nil {
+			return field.InternalError(ipsField, fmt.Errorf("failed to parse 'spec.ips':\n%v\n of the existing ReservedIP %s: %v", r.Spec.IPs, r.Name, err))
+		}
+		if len(spiderpoolip.IPsIntersectionSet(newReservedIPs, existReservedIPs)) > 0 {
+			return field.Forbidden(
+				ipsField,
+				fmt.Sprintf("overlaps with the existing ReservedIP %s", r.Name),
 			)
 		}
 	}
diff --git a/pkg/subnetmanager/subnet_mutate.go b/pkg/subnetmanager/subnet_mutate.go
index c5decbac8..ec26ab629 100644
--- a/pkg/subnetmanager/subnet_mutate.go
+++ b/pkg/subnetmanager/subnet_mutate.go
@@ -5,6 +5,7 @@ package subnetmanager
 
 import (
 	"context"
+	"errors"
 	"fmt"
 
 	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -37,7 +38,7 @@ func (sw *SubnetWebhook) mutateSubnet(ctx context.Context, subnet *spiderpoolv1.
 		} else if spiderpoolip.IsIPv6CIDR(subnet.Spec.Subnet) {
 			version = constant.IPv6
 		} else {
-			return fmt.Errorf("failed to generate 'spec.ipVersion' from 'spec.subnet' %s, nothing to mutate", subnet.Spec.Subnet)
+			return errors.New("invalid 'spec.ipVersion', noting to mutate")
 		}
 
 		subnet.Spec.IPVersion = new(types.IPVersion)
@@ -45,19 +46,6 @@ func (sw *SubnetWebhook) mutateSubnet(ctx context.Context, subnet *spiderpoolv1.
 		logger.Sugar().Infof("Set 'spec.ipVersion' to %d", version)
 	}
 
-	cidr, err := spiderpoolip.CIDRToLabelValue(*subnet.Spec.IPVersion, subnet.Spec.Subnet)
-	if err != nil {
-		return fmt.Errorf("failed to parse 'spec.subnet' %s as a valid label value: %v", subnet.Spec.Subnet, err)
-	}
-
-	if v, ok := subnet.Labels[constant.LabelSubnetCIDR]; !ok || v != cidr {
-		if subnet.Labels == nil {
-			subnet.Labels = make(map[string]string)
-		}
-		subnet.Labels[constant.LabelSubnetCIDR] = cidr
-		logger.Sugar().Infof("Set label %s: %s", constant.LabelSubnetCIDR, cidr)
-	}
-
 	if len(subnet.Spec.IPs) > 1 {
 		mergedIPs, err := spiderpoolip.MergeIPRanges(*subnet.Spec.IPVersion, subnet.Spec.IPs)
 		if err != nil {
diff --git a/pkg/subnetmanager/subnet_validate.go b/pkg/subnetmanager/subnet_validate.go
index be4894ab3..3d8012683 100644
--- a/pkg/subnetmanager/subnet_validate.go
+++ b/pkg/subnetmanager/subnet_validate.go
@@ -32,7 +32,7 @@ func (sw *SubnetWebhook) validateCreateSubnet(ctx context.Context, subnet *spide
 		return field.ErrorList{err}
 	}
 
-	if err := sw.validateSubnetCIDR(ctx, subnet); err != nil {
+	if err := sw.validateSubnetSubnet(ctx, subnet); err != nil {
 		return field.ErrorList{err}
 	}
 
@@ -166,7 +166,7 @@ func (sw *SubnetWebhook) validateSubnetIPVersion(version *types.IPVersion) *fiel
 	return nil
 }
 
-func (sw *SubnetWebhook) validateSubnetCIDR(ctx context.Context, subnet *spiderpoolv1.SpiderSubnet) *field.Error {
+func (sw *SubnetWebhook) validateSubnetSubnet(ctx context.Context, subnet *spiderpoolv1.SpiderSubnet) *field.Error {
 	if err := spiderpoolip.IsCIDR(*subnet.Spec.IPVersion, subnet.Spec.Subnet); err != nil {
 		return field.Invalid(
 			subnetField,
@@ -175,7 +175,6 @@ func (sw *SubnetWebhook) validateSubnetCIDR(ctx context.Context, subnet *spiderp
 		)
 	}
 
-	// TODO(iiiceoo): Use label selector.
 	subnetList := spiderpoolv1.SpiderSubnetList{}
 	if err := sw.List(ctx, &subnetList); err != nil {
 		return field.InternalError(subnetField, fmt.Errorf("failed to list Subnets: %v", err))
@@ -206,6 +205,13 @@ func (sw *SubnetWebhook) validateSubnetCIDR(ctx context.Context, subnet *spiderp
 }
 
 func validateSubnetIPs(version types.IPVersion, subnet string, ips []string) *field.Error {
+	if len(ips) == 0 {
+		return field.Required(
+			ipsField,
+			"requires at least one item",
+		)
+	}
+
 	for i, r := range ips {
 		if err := ippoolmanager.ValidateContainsIPRange(ipsField.Index(i), version, subnet, r); err != nil {
 			return err


Test patch:
diff --git a/pkg/ip/utils_test.go b/pkg/ip/utils_test.go
index afad9ef6d..6631300c1 100644
--- a/pkg/ip/utils_test.go
+++ b/pkg/ip/utils_test.go
@@ -65,32 +65,4 @@ var _ = Describe("IP utils", Label("ip_utils_test"), func() {
 			Expect(ips).To(Equal([]net.IP{net.ParseIP("abcd:1234::1")}))
 		})
 	})
-
-	Describe("Test CIDRToLabelValue", func() {
-		When("Verifying", func() {
-			It("inputs invalid IP version", func() {
-				cidr, err := spiderpoolip.CIDRToLabelValue(constant.InvalidIPVersion, "172.18.40.0/24")
-				Expect(err).To(MatchError(spiderpoolip.ErrInvalidIPVersion))
-				Expect(cidr).To(BeEmpty())
-			})
-
-			It("inputs invalid CIDR address", func() {
-				cidr, err := spiderpoolip.CIDRToLabelValue(constant.IPv4, constant.InvalidCIDR)
-				Expect(err).To(MatchError(spiderpoolip.ErrInvalidCIDRFormat))
-				Expect(cidr).To(BeEmpty())
-			})
-		})
-
-		It("parses IPv4 CIDR address", func() {
-			cidr, err := spiderpoolip.CIDRToLabelValue(constant.IPv4, "172.18.40.0/24")
-			Expect(err).NotTo(HaveOccurred())
-			Expect(cidr).To(Equal("172-18-40-0-24"))
-		})
-
-		It("parses IPv6 CIDR address", func() {
-			cidr, err := spiderpoolip.CIDRToLabelValue(constant.IPv6, "abcd:1234::/120")
-			Expect(err).NotTo(HaveOccurred())
-			Expect(cidr).To(Equal("abcd-1234---120"))
-		})
-	})
 })
diff --git a/pkg/ippoolmanager/ippool_webhook_test.go b/pkg/ippoolmanager/ippool_webhook_test.go
index 7bf02efbb..a77a0c827 100644
--- a/pkg/ippoolmanager/ippool_webhook_test.go
+++ b/pkg/ippoolmanager/ippool_webhook_test.go
@@ -22,7 +22,6 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/manager"
 
 	"github.com/spidernet-io/spiderpool/pkg/constant"
-	spiderpoolip "github.com/spidernet-io/spiderpool/pkg/ip"
 	"github.com/spidernet-io/spiderpool/pkg/ippoolmanager"
 	spiderpoolv1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v1"
 	"github.com/spidernet-io/spiderpool/pkg/logutils"
@@ -64,8 +63,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					APIVersion: fmt.Sprintf("%s/%s", constant.SpiderpoolAPIGroup, constant.SpiderpoolAPIVersionV1),
 				},
 				ObjectMeta: metav1.ObjectMeta{
-					Name:   subnetName,
-					Labels: map[string]string{},
+					Name: subnetName,
 				},
 				Spec: spiderpoolv1.SubnetSpec{},
 			}
@@ -89,8 +87,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					APIVersion: fmt.Sprintf("%s/%s", constant.SpiderpoolAPIGroup, constant.SpiderpoolAPIVersionV1),
 				},
 				ObjectMeta: metav1.ObjectMeta{
-					Name:   existIPPoolName,
-					Labels: map[string]string{},
+					Name: existIPPoolName,
 				},
 				Spec: spiderpoolv1.IPPoolSpec{},
 			}
@@ -126,74 +123,14 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				Expect(err).NotTo(HaveOccurred())
 			})
 
-			It("adds finalizer", func() {
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
-
-				ctx := context.TODO()
-				err := ipPoolWebhook.Default(ctx, ipPoolT)
-				Expect(err).NotTo(HaveOccurred())
-
-				contains := controllerutil.ContainsFinalizer(ipPoolT, constant.SpiderFinalizer)
-				Expect(contains).To(BeTrue())
-			})
-
-			It("failed to parse 'spec.subnet' as a valid label value", func() {
-				ipPoolT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
-
-				ctx := context.TODO()
-				err := ipPoolWebhook.Default(ctx, ipPoolT)
-				Expect(err).NotTo(HaveOccurred())
-
-				v, ok := ipPoolT.Labels[constant.LabelIPPoolCIDR]
-				Expect(ok).To(BeFalse())
-				Expect(v).To(BeEmpty())
-			})
-
-			It("sets CIDR label", func() {
-				subnet := "172.18.40.0/24"
-				ipPoolT.Spec.Subnet = subnet
-
-				ctx := context.TODO()
-				err := ipPoolWebhook.Default(ctx, ipPoolT)
-				Expect(err).NotTo(HaveOccurred())
-
-				cidr, err := spiderpoolip.CIDRToLabelValue(*ipPoolT.Spec.IPVersion, subnet)
-				Expect(err).NotTo(HaveOccurred())
-				Expect(cidr).NotTo(BeEmpty())
-
-				v, ok := ipPoolT.Labels[constant.LabelIPPoolCIDR]
-				Expect(ok).To(BeTrue())
-				Expect(v).To(Equal(cidr))
-			})
-
-			It("is orphan IPPool", func() {
-				ipPoolWebhook.EnableSpiderSubnet = true
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
-
-				ctx := context.TODO()
-				err := ipPoolWebhook.Default(ctx, ipPoolT)
-				Expect(err).NotTo(HaveOccurred())
-
-				owner := metav1.GetControllerOf(ipPoolT)
-				Expect(owner).To(BeNil())
-			})
-
 			It("failed to list Subnets due to some unknown errors", func() {
 				patches := gomonkey.ApplyMethodReturn(fakeClient, "List", constant.ErrUnknown)
 				defer patches.Reset()
 
-				ipVersion := constant.IPv4
-				subnet := "172.18.40.0/24"
-				cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-				Expect(err).NotTo(HaveOccurred())
-				Expect(cidr).NotTo(BeEmpty())
-
 				ipPoolWebhook.EnableSpiderSubnet = true
 				subnetT.SetUID(uuid.NewUUID())
-				subnetT.Labels[constant.LabelSubnetCIDR] = cidr
-				subnetT.Spec.IPVersion = pointer.Int64(ipVersion)
-				subnetT.Spec.Subnet = subnet
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"172.18.40.1-172.18.40.2",
@@ -202,10 +139,12 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				)
 
 				ctx := context.TODO()
-				err = fakeClient.Create(ctx, subnetT)
+				err := fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
-				ipPoolT.Spec.Subnet = subnet
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				ipPoolT.Spec.Subnet = "172.18.40.0/24"
+
 				err = ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -221,17 +160,10 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				patches := gomonkey.ApplyFuncReturn(controllerutil.SetControllerReference, constant.ErrUnknown)
 				defer patches.Reset()
 
-				ipVersion := constant.IPv4
-				subnet := "172.18.40.0/24"
-				cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-				Expect(err).NotTo(HaveOccurred())
-				Expect(cidr).NotTo(BeEmpty())
-
 				ipPoolWebhook.EnableSpiderSubnet = true
 				subnetT.SetUID(uuid.NewUUID())
-				subnetT.Labels[constant.LabelSubnetCIDR] = cidr
-				subnetT.Spec.IPVersion = pointer.Int64(ipVersion)
-				subnetT.Spec.Subnet = subnet
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"172.18.40.1-172.18.40.2",
@@ -240,10 +172,12 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				)
 
 				ctx := context.TODO()
-				err = fakeClient.Create(ctx, subnetT)
+				err := fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
-				ipPoolT.Spec.Subnet = subnet
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				ipPoolT.Spec.Subnet = "172.18.40.0/24"
+
 				err = ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -256,17 +190,10 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			It("sets the reference of the controller Subnet", func() {
-				ipVersion := constant.IPv4
-				subnet := "172.18.50.0/24"
-				cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-				Expect(err).NotTo(HaveOccurred())
-				Expect(cidr).NotTo(BeEmpty())
-
 				ipPoolWebhook.EnableSpiderSubnet = true
 				subnetT.SetUID(uuid.NewUUID())
-				subnetT.Labels[constant.LabelSubnetCIDR] = cidr
-				subnetT.Spec.IPVersion = pointer.Int64(ipVersion)
-				subnetT.Spec.Subnet = subnet
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				subnetT.Spec.Subnet = "172.18.50.0/24"
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"172.18.50.1-172.18.50.2",
@@ -275,14 +202,22 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				)
 
 				ctx := context.TODO()
-				err = fakeClient.Create(ctx, subnetT)
+				err := fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
-				ipPoolT.Spec.Subnet = subnet
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+				ipPoolT.Spec.Subnet = "172.18.50.0/24"
+
 				err = ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
 				controlled := metav1.IsControlledBy(ipPoolT, subnetT)
+
+				// TODO(Icarus9913): maybe fail
+				ownerReference := metav1.GetControllerOf(ipPoolT)
+				fmt.Printf("The SpiderIPPool '%+v' corresponding owner reference: '%+v'", ipPoolT, ownerReference)
+				fmt.Printf("Print SpiderSubnet details: '%+v'", subnetT)
+
 				Expect(controlled).To(BeTrue())
 
 				v, ok := ipPoolT.Labels[constant.LabelIPPoolOwnerSpiderSubnet]
@@ -293,6 +228,17 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				Expect(err).NotTo(HaveOccurred())
 			})
 
+			It("adds finalizer", func() {
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+
+				ctx := context.TODO()
+				err := ipPoolWebhook.Default(ctx, ipPoolT)
+				Expect(err).NotTo(HaveOccurred())
+
+				contains := controllerutil.ContainsFinalizer(ipPoolT, constant.SpiderFinalizer)
+				Expect(contains).To(BeTrue())
+			})
+
 			It("failed to set 'spec.ipVersion' due to the invalid 'spec.subnet'", func() {
 				ipPoolT.Spec.Subnet = constant.InvalidCIDR
 
@@ -322,7 +268,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 			It("failed to merge 'spec.ips' due to the invalid 'spec.ipVersion'", func() {
 				ipPoolT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 				ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 					[]string{
 						"172.18.40.10",
@@ -345,7 +290,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 			It("failed to merge 'spec.ips' due to the invalid 'spec.ips'", func() {
 				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 				ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 					[]string{
 						constant.InvalidIPRange,
@@ -369,7 +313,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			It("merges IPv4 'spec.ips'", func() {
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 				ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 					[]string{
 						"172.18.40.10",
@@ -390,7 +334,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			It("merges IPv6 'spec.ips'", func() {
-				ipPoolT.Spec.Subnet = "abcd:1234::/120"
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv6)
 				ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 					[]string{
 						"abcd:1234::a",
@@ -412,7 +356,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 			It("failed to merge 'spec.excludeIPs' due to the invalid 'spec.ipVersion'", func() {
 				ipPoolT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 				ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs,
 					[]string{
 						"172.18.40.10",
@@ -435,7 +378,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 			It("failed to merge 'spec.excludeIPs' due to the invalid 'spec.ips'", func() {
 				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 				ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs,
 					[]string{
 						constant.InvalidIPRange,
@@ -459,7 +401,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			It("merges IPv4 'spec.excludeIPs'", func() {
-				ipPoolT.Spec.Subnet = "172.18.40.0/24"
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 				ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs,
 					[]string{
 						"172.18.40.10",
@@ -480,7 +422,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			It("merges IPv6 'spec.excludeIPs'", func() {
-				ipPoolT.Spec.Subnet = "abcd:1234::/120"
+				ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv6)
 				ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs,
 					[]string{
 						"abcd:1234::a",
@@ -680,6 +622,40 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			When("Validating 'spec.ips'", func() {
+				It("inputs empty 'spec.ips' while feature SpiderSubnet is enabled", func() {
+					ipPoolWebhook.EnableSpiderSubnet = true
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
+					Expect(err).NotTo(HaveOccurred())
+
+					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
+					Expect(err).NotTo(HaveOccurred())
+
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
+
+					err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
+					Expect(err).NotTo(HaveOccurred())
+				})
+
+				It("inputs empty 'spec.ips'", func() {
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
+
+					ctx := context.TODO()
+					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("inputs invalid 'spec.ips'", func() {
 					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					ipPoolT.Spec.Subnet = "172.18.40.0/24"
@@ -705,24 +681,21 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
 
-				It("exists invalid IPPool in the cluster", func() {
-					ipVersion := constant.IPv4
-					subnet := "172.18.40.0/24"
-					cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-					Expect(err).NotTo(HaveOccurred())
-					Expect(cidr).NotTo(BeEmpty())
+				PIt("failed to list IPPools due to some unknown errors", func() {})
 
-					existIPPoolT.Labels[constant.LabelIPPoolCIDR] = cidr
-					existIPPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					existIPPoolT.Spec.Subnet = subnet
+				PIt("failed to assemble the total IP addresses of the IPPool due to some unknown errors", func() {})
+
+				It("exists invalid IPPool in the cluster", func() {
+					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, constant.InvalidIPRange)
 
 					ctx := context.TODO()
-					err = fakeClient.Create(ctx, existIPPoolT)
+					err := fakeClient.Create(ctx, existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
-					ipPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					ipPoolT.Spec.Subnet = subnet
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
 					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 						[]string{
 							"172.18.40.1-172.18.40.2",
@@ -735,23 +708,16 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				})
 
 				It("overlaps with existing IPPool", func() {
-					ipVersion := constant.IPv4
-					subnet := "172.18.40.0/24"
-					cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-					Expect(err).NotTo(HaveOccurred())
-					Expect(cidr).NotTo(BeEmpty())
-
-					existIPPoolT.Labels[constant.LabelIPPoolCIDR] = cidr
-					existIPPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					existIPPoolT.Spec.Subnet = subnet
+					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.40.10")
 
 					ctx := context.TODO()
-					err = fakeClient.Create(ctx, existIPPoolT)
+					err := fakeClient.Create(ctx, existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
-					ipPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					ipPoolT.Spec.Subnet = subnet
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
 					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
 						[]string{
 							"172.18.40.1-172.18.40.2",
@@ -945,6 +911,37 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
 
+				It("sets owner reference to a Subnet with different 'spec.subnet'", func() {
+					subnetT.SetUID(uuid.NewUUID())
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
+					Expect(err).NotTo(HaveOccurred())
+
+					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
+					Expect(err).NotTo(HaveOccurred())
+
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/25"
+					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("sets owner reference to a terminating Subnet", func() {
 					controllerutil.AddFinalizer(subnetT, constant.SpiderFinalizer)
 					subnetT.SetUID(uuid.NewUUID())
@@ -986,6 +983,10 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					ipPoolWebhook.EnableSpiderSubnet = true
 				})
 
+				PIt("failed to assemble the total IP addresses of the IPPool due to some unknown errors", func() {})
+
+				PIt("failed to assemble the total IP addresses of the Subnet due to some unknown errors", func() {})
+
 				It("is out of the IP range of the Subnet", func() {
 					subnetT.SetUID(uuid.NewUUID())
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
@@ -1189,6 +1190,73 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			When("Validating 'spec.ips'", func() {
+				It("removes all 'spec.ips' while feature SpiderSubnet is enabled", func() {
+					ipPoolWebhook.EnableSpiderSubnet = true
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
+					Expect(err).NotTo(HaveOccurred())
+
+					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
+					Expect(err).NotTo(HaveOccurred())
+
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
+					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					newIPPoolT := ipPoolT.DeepCopy()
+					newIPPoolT.Spec.IPs = nil
+
+					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
+					Expect(err).NotTo(HaveOccurred())
+				})
+
+				It("removes all 'spec.ips'", func() {
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
+					Expect(err).NotTo(HaveOccurred())
+
+					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
+					Expect(err).NotTo(HaveOccurred())
+
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
+					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					newIPPoolT := ipPoolT.DeepCopy()
+					newIPPoolT.Spec.IPs = nil
+
+					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("appends invalid IP range to 'spec.ips'", func() {
 					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					ipPoolT.Spec.Subnet = "172.18.40.0/24"
@@ -1220,24 +1288,21 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
 
-				It("exists invalid IPPool in the cluster", func() {
-					ipVersion := constant.IPv4
-					subnet := "172.18.40.0/24"
-					cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-					Expect(err).NotTo(HaveOccurred())
-					Expect(cidr).NotTo(BeEmpty())
+				PIt("failed to list IPPools due to some unknown errors", func() {})
 
-					existIPPoolT.Labels[constant.LabelIPPoolCIDR] = cidr
-					existIPPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					existIPPoolT.Spec.Subnet = subnet
+				PIt("failed to assemble the total IP addresses of the IPPool due to some unknown errors", func() {})
+
+				It("exists invalid IPPool in the cluster", func() {
+					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, constant.InvalidIPRange)
 
 					ctx := context.TODO()
-					err = fakeClient.Create(ctx, existIPPoolT)
+					err := fakeClient.Create(ctx, existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
-					ipPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					ipPoolT.Spec.Subnet = subnet
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
 					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs, "172.18.40.1-172.18.40.2")
 
 					newIPPoolT := ipPoolT.DeepCopy()
@@ -1248,23 +1313,16 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				})
 
 				It("overlaps with existing IPPool", func() {
-					ipVersion := constant.IPv4
-					subnet := "172.18.40.0/24"
-					cidr, err := spiderpoolip.CIDRToLabelValue(ipVersion, subnet)
-					Expect(err).NotTo(HaveOccurred())
-					Expect(cidr).NotTo(BeEmpty())
-
-					existIPPoolT.Labels[constant.LabelIPPoolCIDR] = cidr
-					existIPPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					existIPPoolT.Spec.Subnet = subnet
+					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.40.10")
 
 					ctx := context.TODO()
-					err = fakeClient.Create(ctx, existIPPoolT)
+					err := fakeClient.Create(ctx, existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
-					ipPoolT.Spec.IPVersion = pointer.Int64(ipVersion)
-					ipPoolT.Spec.Subnet = subnet
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/24"
 					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs, "172.18.40.1-172.18.40.2")
 
 					newIPPoolT := ipPoolT.DeepCopy()
@@ -1425,6 +1483,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			})
 
 			When("Validating the IP addresses being used", func() {
+				PIt("failed to assemble the total IP addresses of the IPPool due to some unknown errors", func() {})
+
 				It("removes IP range that is being used by IPPool", func() {
 					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					ipPoolT.Spec.Subnet = "172.18.40.0/24"
@@ -1492,6 +1552,35 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
 
+				It("updates the IPPool that sets the owner reference to a Subnet with different 'spec.subnet'", func() {
+					subnetT.SetUID(uuid.NewUUID())
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
+					Expect(err).NotTo(HaveOccurred())
+
+					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
+					Expect(err).NotTo(HaveOccurred())
+
+					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					ipPoolT.Spec.Subnet = "172.18.40.0/25"
+					ipPoolT.Spec.IPs = append(ipPoolT.Spec.IPs, "172.18.40.1-172.18.40.2")
+
+					newIPPoolT := ipPoolT.DeepCopy()
+					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "172.18.40.10")
+
+					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("updates the IPPool that sets the owner reference to a terminating Subnet", func() {
 					controllerutil.AddFinalizer(subnetT, constant.SpiderFinalizer)
 					subnetT.SetUID(uuid.NewUUID())
@@ -1531,6 +1620,10 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					ipPoolWebhook.EnableSpiderSubnet = true
 				})
 
+				PIt("failed to assemble the total IP addresses of the IPPool due to some unknown errors", func() {})
+
+				PIt("failed to assemble the total IP addresses of the Subnet due to some unknown errors", func() {})
+
 				It("is out of the IP range of the Subnet", func() {
 					subnetT.SetUID(uuid.NewUUID())
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
diff --git a/pkg/reservedipmanager/reservedip_webhook_test.go b/pkg/reservedipmanager/reservedip_webhook_test.go
index c09f43912..22cf9b01b 100644
--- a/pkg/reservedipmanager/reservedip_webhook_test.go
+++ b/pkg/reservedipmanager/reservedip_webhook_test.go
@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"sync/atomic"
 
+	"github.com/agiledragon/gomonkey/v2"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -41,8 +42,8 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 
 	Describe("Test ReservedIPWebhook's method", func() {
 		var count uint64
-		var rIPName string
-		var rIPT *spiderpoolv1.SpiderReservedIP
+		var rIPName, existRIPName string
+		var rIPT, existRIPT *spiderpoolv1.SpiderReservedIP
 
 		BeforeEach(func() {
 			reservedipmanager.WebhookLogger = logutils.Logger.Named("ReservedIP-Webhook")
@@ -61,6 +62,18 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 				},
 				Spec: spiderpoolv1.ReservedIPSpec{},
 			}
+
+			existRIPName = fmt.Sprintf("z-exist-reservedip-%v", count)
+			existRIPT = &spiderpoolv1.SpiderReservedIP{
+				TypeMeta: metav1.TypeMeta{
+					Kind:       constant.SpiderReservedIPKind,
+					APIVersion: fmt.Sprintf("%s/%s", constant.SpiderpoolAPIGroup, constant.SpiderpoolAPIVersionV1),
+				},
+				ObjectMeta: metav1.ObjectMeta{
+					Name: existRIPName,
+				},
+				Spec: spiderpoolv1.ReservedIPSpec{},
+			}
 		})
 
 		var deleteOption *client.DeleteOptions
@@ -75,6 +88,9 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 			ctx := context.TODO()
 			err := fakeClient.Delete(ctx, rIPT, deleteOption)
 			Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred())
+
+			err = fakeClient.Delete(ctx, existRIPT, deleteOption)
+			Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred())
 		})
 
 		Describe("Default", func() {
@@ -245,6 +261,14 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 			})
 
 			When("Validating 'spec.ips'", func() {
+				It("inputs empty 'spec.ips'", func() {
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+
+					ctx := context.TODO()
+					err := rIPWebhook.ValidateCreate(ctx, rIPT)
+					Expect(err).NotTo(HaveOccurred())
+				})
+
 				It("inputs invalid 'spec.ips'", func() {
 					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					rIPT.Spec.IPs = append(rIPT.Spec.IPs, constant.InvalidIPRange)
@@ -253,6 +277,63 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 					err := rIPWebhook.ValidateCreate(ctx, rIPT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
+
+				It("failed to list ReservedIPs due to some unknown errors", func() {
+					patches := gomonkey.ApplyMethodReturn(fakeClient, "List", constant.ErrUnknown)
+					defer patches.Reset()
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					ctx := context.TODO()
+					err := rIPWebhook.ValidateCreate(ctx, rIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
+				It("exists invalid ReservedIPs in the cluster", func() {
+					existRIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existRIPT.Spec.IPs = append(existRIPT.Spec.IPs, constant.InvalidIPRange)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, existRIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					err = rIPWebhook.ValidateCreate(ctx, rIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
+				It("overlaps with existing ReservedIP", func() {
+					existRIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existRIPT.Spec.IPs = append(existRIPT.Spec.IPs, "172.18.40.10")
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, existRIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					err = rIPWebhook.ValidateCreate(ctx, rIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
 			})
 
 			It("creates IPv4 ReservedIP with all fields valid", func() {
@@ -344,6 +425,61 @@ var _ = Describe("ReservedIPWebhook", Label("reservedip_webhook_test"), func() {
 					err := rIPWebhook.ValidateUpdate(ctx, rIPT, newRIPT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
+
+				It("failed to list ReservedIPs due to some unknown errors", func() {
+					patches := gomonkey.ApplyMethodReturn(fakeClient, "List", constant.ErrUnknown)
+					defer patches.Reset()
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs, "172.18.40.1-172.18.40.2")
+
+					newRIPT := rIPT.DeepCopy()
+					newRIPT.Spec.IPs = append(newRIPT.Spec.IPs, "172.18.40.10")
+
+					ctx := context.TODO()
+					err := rIPWebhook.ValidateUpdate(ctx, rIPT, newRIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
+				It("exists invalid ReservedIPs in the cluster", func() {
+					existRIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existRIPT.Spec.IPs = append(existRIPT.Spec.IPs, constant.InvalidIPRange)
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, existRIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs, "172.18.40.1-172.18.40.2")
+					err = fakeClient.Create(ctx, rIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					newRIPT := rIPT.DeepCopy()
+					newRIPT.Spec.IPs = append(newRIPT.Spec.IPs, "172.18.40.10")
+
+					err = rIPWebhook.ValidateUpdate(ctx, rIPT, newRIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
+				It("overlaps with existing ReservedIP", func() {
+					existRIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					existRIPT.Spec.IPs = append(existRIPT.Spec.IPs, "172.18.40.10")
+
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, existRIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					rIPT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					rIPT.Spec.IPs = append(rIPT.Spec.IPs, "172.18.40.1-172.18.40.2")
+					err = fakeClient.Create(ctx, rIPT)
+					Expect(err).NotTo(HaveOccurred())
+
+					newRIPT := rIPT.DeepCopy()
+					newRIPT.Spec.IPs = append(newRIPT.Spec.IPs, "172.18.40.10")
+
+					err = rIPWebhook.ValidateUpdate(ctx, rIPT, newRIPT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
 			})
 
 			It("deletes ReservedIP", func() {
diff --git a/pkg/subnetmanager/subnet_webhook_test.go b/pkg/subnetmanager/subnet_webhook_test.go
index 6fe65fb45..9d8c4a90b 100644
--- a/pkg/subnetmanager/subnet_webhook_test.go
+++ b/pkg/subnetmanager/subnet_webhook_test.go
@@ -106,7 +106,7 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			It("adds finalizer", func() {
-				subnetT.Spec.Subnet = "172.18.40.0/24"
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 
 				ctx := context.TODO()
 				err := subnetWebhook.Default(ctx, subnetT)
@@ -116,36 +116,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 				Expect(contains).To(BeTrue())
 			})
 
-			It("failed to parse 'spec.subnet' as a valid label value", func() {
-				subnetT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				subnetT.Spec.Subnet = "172.18.40.0/24"
-
-				ctx := context.TODO()
-				err := subnetWebhook.Default(ctx, subnetT)
-				Expect(err).NotTo(HaveOccurred())
-
-				v, ok := subnetT.Labels[constant.LabelSubnetCIDR]
-				Expect(ok).To(BeFalse())
-				Expect(v).To(BeEmpty())
-			})
-
-			It("sets CIDR label", func() {
-				subnet := "172.18.40.0/24"
-				subnetT.Spec.Subnet = subnet
-
-				ctx := context.TODO()
-				err := subnetWebhook.Default(ctx, subnetT)
-				Expect(err).NotTo(HaveOccurred())
-
-				cidr, err := spiderpoolip.CIDRToLabelValue(*subnetT.Spec.IPVersion, subnet)
-				Expect(err).NotTo(HaveOccurred())
-				Expect(cidr).NotTo(BeEmpty())
-
-				v, ok := subnetT.Labels[constant.LabelSubnetCIDR]
-				Expect(ok).To(BeTrue())
-				Expect(v).To(Equal(cidr))
-			})
-
 			It("failed to set 'spec.ipVersion' due to the invalid 'spec.subnet'", func() {
 				subnetT.Spec.Subnet = constant.InvalidCIDR
 
@@ -175,7 +145,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 
 			It("failed to merge 'spec.ips' due to the invalid 'spec.ipVersion'", func() {
 				subnetT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"172.18.40.10",
@@ -198,7 +167,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 
 			It("failed to merge 'spec.ips' due to the invalid 'spec.ips'", func() {
 				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						constant.InvalidIPRange,
@@ -222,7 +190,7 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			It("merges IPv4 'spec.ips'", func() {
-				subnetT.Spec.Subnet = "172.18.40.0/24"
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"172.18.40.10",
@@ -243,7 +211,7 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			It("merges IPv6 'spec.ips'", func() {
-				subnetT.Spec.Subnet = "abcd:1234::/120"
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv6)
 				subnetT.Spec.IPs = append(subnetT.Spec.IPs,
 					[]string{
 						"abcd:1234::a",
@@ -265,7 +233,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 
 			It("failed to merge 'spec.excludeIPs' due to the invalid 'spec.ipVersion'", func() {
 				subnetT.Spec.IPVersion = pointer.Int64(constant.InvalidIPVersion)
-				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.ExcludeIPs = append(subnetT.Spec.ExcludeIPs,
 					[]string{
 						"172.18.40.10",
@@ -288,7 +255,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 
 			It("failed to merge 'spec.excludeIPs' due to the invalid 'spec.ips'", func() {
 				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-				subnetT.Spec.Subnet = "172.18.40.0/24"
 				subnetT.Spec.ExcludeIPs = append(subnetT.Spec.ExcludeIPs,
 					[]string{
 						constant.InvalidIPRange,
@@ -312,7 +278,7 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			It("merges IPv4 'spec.excludeIPs'", func() {
-				subnetT.Spec.Subnet = "172.18.40.0/24"
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 				subnetT.Spec.ExcludeIPs = append(subnetT.Spec.ExcludeIPs,
 					[]string{
 						"172.18.40.10",
@@ -333,7 +299,7 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			It("merges IPv6 'spec.excludeIPs'", func() {
-				subnetT.Spec.Subnet = "abcd:1234::/120"
+				subnetT.Spec.IPVersion = pointer.Int64(constant.IPv6)
 				subnetT.Spec.ExcludeIPs = append(subnetT.Spec.ExcludeIPs,
 					[]string{
 						"abcd:1234::a",
@@ -516,6 +482,15 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			When("Validating 'spec.ips'", func() {
+				It("inputs empty 'spec.ips'", func() {
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+
+					ctx := context.TODO()
+					err := subnetWebhook.ValidateCreate(ctx, subnetT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("inputs invalid 'spec.ips'", func() {
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					subnetT.Spec.Subnet = "172.18.40.0/24"
@@ -812,6 +787,24 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 			})
 
 			When("Validating 'spec.ips'", func() {
+				It("removes all 'spec.ips'", func() {
+					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
+					subnetT.Spec.Subnet = "172.18.40.0/24"
+					subnetT.Spec.IPs = append(subnetT.Spec.IPs,
+						[]string{
+							"172.18.40.1-172.18.40.2",
+							"172.18.40.10",
+						}...,
+					)
+
+					newSubnetT := subnetT.DeepCopy()
+					newSubnetT.Spec.IPs = nil
+
+					ctx := context.TODO()
+					err := subnetWebhook.ValidateUpdate(ctx, subnetT, newSubnetT)
+					Expect(apierrors.IsInvalid(err)).To(BeTrue())
+				})
+
 				It("appends invalid IP range to 'spec.ips'", func() {
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
 					subnetT.Spec.Subnet = "172.18.40.0/24"
diff --git a/test/e2e/affinity/affinity_test.go b/test/e2e/affinity/affinity_test.go
index 3e9d8281e..7b1c0b37e 100644
--- a/test/e2e/affinity/affinity_test.go
+++ b/test/e2e/affinity/affinity_test.go
@@ -354,9 +354,11 @@ var _ = Describe("test Affinity", Label("affinity"), func() {
 		var newPodList *corev1.PodList
 		var defaultV4PoolNameList, defaultV6PoolNameList []string
 		const stsOriginialNum = int(1)
-		statefulSetName = "sts" + tools.RandomName()
 
 		BeforeEach(func() {
+			// test statefulSet name
+			statefulSetName = "sts" + tools.RandomName()
+
 			// Create IPv4 pools and IPv6 pools
 			if frame.Info.IpV4Enabled {
 				v4PoolName, v4PoolObj = common.GenerateExampleIpv4poolObject(5)
diff --git a/test/e2e/annotation/annotation_test.go b/test/e2e/annotation/annotation_test.go
index cabf10b0f..833cc3e38 100644
--- a/test/e2e/annotation/annotation_test.go
+++ b/test/e2e/annotation/annotation_test.go
@@ -453,13 +453,14 @@ var _ = Describe("test annotation", Label("annotation"), func() {
 	Context("Spiderpool will successively try to allocate IP in the order of the elements in the IPPool array until the first allocation succeeds or all fail", func() {
 		var v4PoolNameList1, v6PoolNameList1, v4PoolNameList2, v6PoolNameList2 []string
 		var err error
-		var deployName = "deploy" + tools.RandomName()
+		var deployName string
 		var (
 			podOriginialNum int = 1
 			podScaleupNum   int = 2
 			ippoolIpNum     int = 1
 		)
 		BeforeEach(func() {
+			deployName = "deploy" + tools.RandomName()
 			// Create one ippool to be used as backup ippool
 			if frame.Info.IpV4Enabled {
 				if frame.Info.SpiderSubnetEnabled {
diff --git a/test/e2e/subnet/subnet_test.go b/test/e2e/subnet/subnet_test.go
index 01bcc9825..f06551c06 100644
--- a/test/e2e/subnet/subnet_test.go
+++ b/test/e2e/subnet/subnet_test.go
@@ -476,16 +476,16 @@ var _ = Describe("test subnet", Label("subnet"), func() {
 	})
 
 	Context("Validity of fields in subnet.spec", func() {
-		var deployName string = "deploy" + tools.RandomName()
 		var fixedIPNumber string = "+0"
 		var deployOriginiaNum int32 = 1
+		var deployName string
 
 		BeforeEach(func() {
+			deployName = "deploy" + tools.RandomName()
 			v4SubnetName, v4SubnetObject = common.GenerateExampleV4SubnetObject(10)
 			Expect(v4SubnetObject).NotTo(BeNil())
 			v6SubnetName, v6SubnetObject = common.GenerateExampleV6SubnetObject(10)
 			Expect(v6SubnetObject).NotTo(BeNil())
-
 			// Delete namespaces and delete subnets
 			DeferCleanup(func() {
 				GinkgoWriter.Printf("delete v4 subnet %v, v6 subnet %v \n", v4SubnetName, v6SubnetName)
@@ -835,28 +835,21 @@ var _ = Describe("test subnet", Label("subnet"), func() {
 			Eventually(func() bool {
 				podList, err = frame.GetPodListByLabel(deployYaml.Spec.Template.Labels)
 				if nil != err {
-					GinkgoWriter.Printf("failed to get pod list %v", err)
+					GinkgoWriter.Printf("failed to get pod list %v \n", err)
 					return false
 				}
-				if len(podList.Items) == 0 {
+				// Compare Pod List numbers
+				if len(podList.Items) != int(deployOriginiaNum) {
 					return false
 				}
-				for _, pod := range podList.Items {
-					ctx, cancel = context.WithTimeout(context.Background(), common.EventOccurTimeout)
-					defer cancel()
-					err = frame.WaitExceptEventOccurred(ctx, common.OwnerPod, pod.Name, namespace, common.CNIFailedToSetUpNetwork)
-					if err != nil {
-						GinkgoWriter.Printf("failed to get event %v", err)
-						// https://github.com/spidernet-io/spiderpool/issues/1329
-						// Probable failure to fetch event or event is swiped and never fetched,
-						// restart the pod and let it fetch again
-						Expect(frame.DeletePod(pod.Name, namespace)).NotTo(HaveOccurred())
-						return false
-					}
-				}
 				return true
 			}, common.PodStartTimeout, common.ForcedWaitingTime).Should(BeTrue())
 
+			ctx, cancel = context.WithTimeout(context.Background(), common.EventOccurTimeout)
+			defer cancel()
+			for _, pod := range podList.Items {
+				err = frame.WaitExceptEventOccurred(ctx, common.OwnerPod, pod.Name, namespace, common.CNIFailedToSetUpNetwork)
+			}
 			Expect(frame.DeleteDeployment(deployName, namespace)).NotTo(HaveOccurred())
 		})
 	})