Repository: spidernet-io/spiderpool
Pull request #1422 (2023-03-10 07:05:00)

IP garbage collection
implement IP garbage collection

Signed-off-by: Icarus9913 [icaruswu66@qq.com](mailto:icaruswu66@qq.com)


Patch:
diff --git a/pkg/gcmanager/gc_manager.go b/pkg/gcmanager/gc_manager.go
index b5903f33d..e59de8003 100644
--- a/pkg/gcmanager/gc_manager.go
+++ b/pkg/gcmanager/gc_manager.go
@@ -142,8 +142,8 @@ func (s *SpiderGC) Start(ctx context.Context) error {
 	return nil
 }
 
+// TODO(Icarus9913): implement me
 func (s *SpiderGC) GetPodDatabase() PodDBer {
-	// TODO (Icarus9913): ??????
 	return s.PodDB
 }
 
@@ -156,6 +156,6 @@ func (s *SpiderGC) TriggerGCAll() {
 	}
 }
 
+// TODO(Icarus9913): implement me
 func (s *SpiderGC) Health() {
-	//TODO (Icarus9913): implement me
 }
diff --git a/pkg/gcmanager/pod_cache.go b/pkg/gcmanager/pod_cache.go
index 020da5639..731d303ee 100644
--- a/pkg/gcmanager/pod_cache.go
+++ b/pkg/gcmanager/pod_cache.go
@@ -134,7 +134,11 @@ func (s *SpiderGC) buildPodEntry(oldPod, currentPod *corev1.Pod, deleted bool) (
 	if deleted {
 		// check StatefulSet pod, we will trace it if its controller StatefulSet object was deleted or decreased its replicas and the pod index was out of the replicas.
 		if s.gcConfig.EnableStatefulSet && ownerRef != nil && ownerRef.Kind == constant.KindStatefulSet {
-			isValidStsPod := s.stsMgr.IsValidStatefulSetPod(context.TODO(), currentPod.Namespace, currentPod.Name)
+			isValidStsPod, err := s.stsMgr.IsValidStatefulSetPod(context.TODO(), currentPod.Namespace, currentPod.Name, ownerRef.Kind)
+			if nil != err {
+				return nil, err
+			}
+
 			// StatefulSet pod restarted, no need to trace it.
 			if isValidStsPod {
 				return nil, nil
diff --git a/pkg/gcmanager/pod_informer.go b/pkg/gcmanager/pod_informer.go
index db6695fe9..1ad0f4746 100644
--- a/pkg/gcmanager/pod_informer.go
+++ b/pkg/gcmanager/pod_informer.go
@@ -38,12 +38,7 @@ func (s *SpiderGC) onPodAdd(obj interface{}) {
 		return
 	}
 
-	pod, ok := obj.(*corev1.Pod)
-	if !ok {
-		logger.Sugar().Errorf("onPodAdd: failed to assert object '%+v' to k8s Pod", obj)
-		return
-	}
-
+	pod := obj.(*corev1.Pod)
 	podEntry, err := s.buildPodEntry(nil, pod, false)
 	if nil != err {
 		logger.Sugar().Errorf("onPodAdd: failed to build Pod Entry '%s/%s', error: %v", pod.Namespace, pod.Name, err)
@@ -52,7 +47,6 @@ func (s *SpiderGC) onPodAdd(obj interface{}) {
 
 	// flush the pod database
 	if podEntry != nil {
-		// TODO (Icarus9913): print tracing pod IPs with debug log level
 		err = s.GetPodDatabase().ApplyPodEntry(podEntry)
 		if nil != err {
 			logger.Sugar().Errorf("onPodAdd: failed to apply Pod Entry '%s/%s', error: %v", pod.Namespace, pod.Name, err)
@@ -67,18 +61,8 @@ func (s *SpiderGC) onPodUpdate(oldObj interface{}, newObj interface{}) {
 		return
 	}
 
-	oldPod, ok := oldObj.(*corev1.Pod)
-	if !ok {
-		logger.Sugar().Errorf("onPodUpdate: failed to assert oldObj '%+v' to k8s Pod", oldPod)
-		return
-	}
-
-	pod, ok := newObj.(*corev1.Pod)
-	if !ok {
-		logger.Sugar().Errorf("onPodUpdate: failed to assert newObj '%+v' to k8s Pod", newObj)
-		return
-	}
-
+	oldPod := oldObj.(*corev1.Pod)
+	pod := newObj.(*corev1.Pod)
 	podEntry, err := s.buildPodEntry(oldPod, pod, false)
 	if nil != err {
 		logger.Sugar().Errorf("onPodUpdate: failed to build Pod Entry '%s/%s', error: %v", pod.Namespace, pod.Name, err)
@@ -87,7 +71,6 @@ func (s *SpiderGC) onPodUpdate(oldObj interface{}, newObj interface{}) {
 
 	// flush the pod database
 	if podEntry != nil {
-		// TODO (Icarus9913): print tracing pod IPs with debug log level
 		err = s.GetPodDatabase().ApplyPodEntry(podEntry)
 		if nil != err {
 			logger.Sugar().Errorf("onPodUpdate: failed to apply Pod Entry '%s/%s', error: %v", pod.Namespace, pod.Name, err)
@@ -102,14 +85,8 @@ func (s *SpiderGC) onPodDel(obj interface{}) {
 		return
 	}
 
-	pod, ok := obj.(*corev1.Pod)
-	if !ok {
-		logger.Sugar().Errorf("onPodDel: failed to assert object '%+v' to k8s Pod", obj)
-		return
-	}
-
+	pod := obj.(*corev1.Pod)
 	logger.Sugar().Infof("onPodDel: receive pod '%s/%s' deleted event", pod.Namespace, pod.Name)
-
 	podEntry, err := s.buildPodEntry(nil, pod, true)
 	if nil != err {
 		logger.Sugar().Errorf("onPodDel: failed to build Pod Entry '%s/%s', error: %v", pod.Namespace, pod.Name, err)
diff --git a/pkg/gcmanager/scanAll_IPPool.go b/pkg/gcmanager/scanAll_IPPool.go
index e6edd723b..fe32eab86 100644
--- a/pkg/gcmanager/scanAll_IPPool.go
+++ b/pkg/gcmanager/scanAll_IPPool.go
@@ -5,9 +5,19 @@ package gcmanager
 
 import (
 	"context"
+	"fmt"
+	"strings"
 	"time"
 
+	"go.uber.org/zap"
+	apierrors "k8s.io/apimachinery/pkg/api/errors"
+
+	"github.com/spidernet-io/spiderpool/pkg/constant"
 	spiderpoolv1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v1"
+	"github.com/spidernet-io/spiderpool/pkg/logutils"
+	"github.com/spidernet-io/spiderpool/pkg/metric"
+	"github.com/spidernet-io/spiderpool/pkg/types"
+	"github.com/spidernet-io/spiderpool/pkg/utils/convert"
 )
 
 // monitorGCSignal will monitor signal from CLI, DefaultGCInterval
@@ -59,143 +69,190 @@ func (s *SpiderGC) monitorGCSignal(ctx context.Context) {
 
 // executeScanAll scans the whole pod and whole IPPoolList
 func (s *SpiderGC) executeScanAll(ctx context.Context) {
-	// poolList, err := s.ippoolMgr.ListIPPools(ctx)
-	// if apierrors.IsNotFound(err) {
-	// 	logger.Sugar().Warnf("scan all failed, ippoolList not found!")
-	// 	return
-	// }
-
-	// if nil != err {
-	// 	logger.Sugar().Errorf("scan all failed: '%v'", err)
-	// 	return
-	// }
-
-	// for _, pool := range poolList.Items {
-	// 	logger.Sugar().Debugf("checking IPPool '%s'", pool.Name)
-
-	// 	for poolIP, poolIPAllocation := range pool.Status.AllocatedIPs {
-	// 		scanAllLogger := logger.With(
-	// 			zap.String("podNS", poolIPAllocation.Namespace),
-	// 			zap.String("podName", poolIPAllocation.Pod),
-	// 			zap.String("podUID", poolIPAllocation.UID),
-	// 		)
-
-	// 		podYaml, err := s.podMgr.GetPodByName(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod)
-	// 		if err != nil {
-	// 			wrappedLog := scanAllLogger.With(zap.String("gc-reason", "pod not found in k8s but still exists in IPPool allocation"))
-
-	// 			// case: The pod in IPPool's ip-allocationDetail is not exist in k8s
-	// 			if apierrors.IsNotFound(err) {
-	// 				check StatefulSet pod whether need to clean up its IP and Endpoint or not
-	// 				if s.gcConfig.EnableStatefulSet && poolIPAllocation.OwnerControllerType == constant.KindStatefulSet {
-	// 					isValidStsPod, err := s.stsMgr.IsValidStatefulSetPod(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod, poolIPAllocation.OwnerControllerType)
-	// 					if nil != err {
-	// 						scanAllLogger.Sugar().Errorf("failed to check StatefulSet pod '%s/%s' IP '%s' should be cleaned or not, error: %v",
-	// 							poolIPAllocation.Namespace, poolIPAllocation.Pod, poolIP, err)
-	// 						continue
-	// 					}
-
-	// 					if isValidStsPod {
-	// 						scanAllLogger.Sugar().Warnf("no deed to release IP '%s' for StatefulSet pod '%s/%s'",
-	// 							poolIP, poolIPAllocation.Namespace, poolIPAllocation.Pod)
-	// 						continue
-	// 					}
-	// 				}
-
-	// 				err = s.releaseSingleIPAndRemoveWEPFinalizer(logutils.IntoContext(ctx, wrappedLog), pool.Name, poolIP, poolIPAllocation)
-	// 				if nil != err {
-	// 					wrappedLog.Error(err.Error())
-	// 					continue
-	// 				}
-
-	// 				// clean up single IP and remove its corresponding SpiderEndpoint successfully, just continue to the next poolIP
-	// 				continue
-	// 			}
-
-	// 			wrappedLog.Sugar().Errorf("check pod from kubernetes failed with error '%v'", err)
-	// 			continue
-	// 		}
-
-	// 		// check pod status phase with its yaml
-	// 		podEntry, err := s.buildPodEntry(nil, podYaml, false)
-	// 		if nil != err {
-	// 			scanAllLogger.Sugar().Errorf("failed to build podEntry '%s/%s' in scanAll, error: %v", poolIPAllocation.Namespace, poolIPAllocation.Pod, err)
-	// 			continue
-	// 		}
-
-	// 		// case: The pod in IPPool's ip-allocationDetail is also exist in k8s, but the pod is in 'Terminating|Succeeded|Failed' status phase
-	// 		if podEntry != nil {
-	// 			if time.Now().UTC().After(podEntry.TracingStopTime) {
-	// 				wrappedLog := scanAllLogger.With(zap.String("gc-reason", "pod is out of time"))
-	// 				err = s.releaseSingleIPAndRemoveWEPFinalizer(logutils.IntoContext(ctx, wrappedLog), pool.Name, poolIP, poolIPAllocation)
-	// 				if nil != err {
-	// 					wrappedLog.Error(err.Error())
-	// 					continue
-	// 				}
-	// 			} else {
-	// 				// otherwise, flush the PodEntry database and let tracePodWorker to solve it if the current controller is elected master.
-	// 				if s.leader.IsElected() {
-	// 					err = s.PodDB.ApplyPodEntry(podEntry)
-	// 					if nil != err {
-	// 						scanAllLogger.Error(err.Error())
-	// 						continue
-	// 					}
-
-	// 					scanAllLogger.With(zap.String("tracing-reason", string(podEntry.PodTracingReason))).
-	// 						Sugar().Infof("update podEntry '%s/%s' successfully", poolIPAllocation.Namespace, poolIPAllocation.Pod)
-	// 				}
-	// 			}
-	// 		} else {
-	// 			endpoint, err := s.wepMgr.GetEndpointByName(ctx, podYaml.Namespace, podYaml.Name)
-	// 			if err != nil {
-	// 				scanAllLogger.Sugar().Errorf("failed to get Endpoint '%s/%s': %v", podYaml.Namespace, podYaml.Name, err)
-	// 				continue
-	// 			}
-
-	// 			// case: The pod in IPPool's ip-allocationDetail is also exist in k8s, but the IP corresponding allocation containerID is different with wep current containerID
-	// 			if endpoint.Status.Current != nil && endpoint.Status.Current.ContainerID != poolIPAllocation.UID {
-	// 				wrappedLog := scanAllLogger.With(zap.String("gc-reason", "IPPoolAllocation containerID is different with wep current containerID"))
-	// 				// release IP but no need to remove wep finalizer
-	// 				err = s.ippoolMgr.ReleaseIP(ctx, pool.Name, []types.IPAndCID{{
-	// 					IP:          poolIP,
-	// 					ContainerID: poolIPAllocation.UID},
-	// 				})
-	// 				if nil != err {
-	// 					wrappedLog.Sugar().Errorf("failed to release ip '%s', error: '%v'", poolIP, err)
-	// 					continue
-	// 				}
-
-	// 				wrappedLog.Sugar().Infof("release ip '%s' successfully!", poolIP)
-	// 			}
-	// 		}
-	// 	}
-	// 	logger.Sugar().Debugf("task checking IPPool '%s' is completed", pool.Name)
-	// }
+	poolList, err := s.ippoolMgr.ListIPPools(ctx, constant.UseCache)
+	if apierrors.IsNotFound(err) {
+		logger.Sugar().Warnf("scan all failed, ippoolList not found!")
+		return
+	}
+
+	if nil != err {
+		logger.Sugar().Errorf("scan all failed: '%v'", err)
+		return
+	}
+
+	for _, pool := range poolList.Items {
+		logger.Sugar().Debugf("checking IPPool '%s'", pool.Name)
+		poolAllocatedIPs, err := convert.UnmarshalIPPoolAllocatedIPs(pool.Status.AllocatedIPs)
+		if nil != err {
+			logger.Sugar().Errorf("failed to parse IPPool '%v' status AllocatedIPs, error: %v", pool, err)
+			continue
+		}
+
+		for poolIP, poolIPAllocation := range poolAllocatedIPs {
+			scanAllLogger := logger.With(
+				zap.String("podNS", poolIPAllocation.Namespace),
+				zap.String("podName", poolIPAllocation.Pod),
+				zap.String("podUID", poolIPAllocation.UID),
+			)
+
+			podYaml, err := s.podMgr.GetPodByName(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod, constant.UseCache)
+			if err != nil {
+				wrappedLog := scanAllLogger.With(zap.String("gc-reason", "pod not found in k8s but still exists in IPPool allocation"))
+
+				// case: The pod in IPPool's ip-allocationDetail is not exist in k8s
+				if apierrors.IsNotFound(err) {
+					isBadIP := false
+					endpoint, err := s.wepMgr.GetEndpointByName(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod, constant.UseCache)
+					if nil != err {
+						if apierrors.IsNotFound(err) {
+							// the corresponding SpiderEndpoint is also not exist
+							isBadIP = true
+						} else {
+							wrappedLog.Error(err.Error())
+							continue
+						}
+					} else {
+						if s.gcConfig.EnableStatefulSet && endpoint.Status.OwnerControllerType == constant.KindStatefulSet {
+							isValidStsPod, err := s.stsMgr.IsValidStatefulSetPod(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod, constant.KindStatefulSet)
+							if nil != err {
+								scanAllLogger.Sugar().Errorf("failed to check StatefulSet pod '%s/%s' IP '%s' should be cleaned or not, error: %v",
+									poolIPAllocation.Namespace, poolIPAllocation.Pod, poolIP, err)
+								continue
+							}
+							if isValidStsPod {
+								scanAllLogger.Sugar().Warnf("no deed to release IP '%s' for StatefulSet pod '%s/%s'",
+									poolIP, poolIPAllocation.Namespace, poolIPAllocation.Pod)
+								continue
+							} else {
+								isBadIP = true
+							}
+						}
+					}
+
+					if isBadIP {
+						wrappedLog.Sugar().Warnf("found IPPool '%s' legacy IP '%s', try to release it", pool.Name, poolIP)
+						err = s.releaseSingleIPAndRemoveWEPFinalizer(logutils.IntoContext(ctx, wrappedLog), pool.Name, poolIP, poolIPAllocation)
+						if nil != err {
+							wrappedLog.Error(err.Error())
+							continue
+						}
+						// clean up single IP and remove its corresponding SpiderEndpoint successfully, just continue to the next poolIP
+						continue
+					}
+				}
+
+				wrappedLog.Sugar().Errorf("check pod from kubernetes failed with error '%v'", err)
+				continue
+			}
+
+			// check pod status phase with its yaml
+			podEntry, err := s.buildPodEntry(nil, podYaml, false)
+			if nil != err {
+				scanAllLogger.Sugar().Errorf("failed to build podEntry '%s/%s' in scanAll, error: %v", poolIPAllocation.Namespace, poolIPAllocation.Pod, err)
+				continue
+			}
+
+			// case: The pod in IPPool's ip-allocationDetail is also exist in k8s, but the pod is in 'Terminating|Succeeded|Failed' status phase
+			if podEntry != nil {
+				if time.Now().UTC().After(podEntry.TracingStopTime) {
+					wrappedLog := scanAllLogger.With(zap.String("gc-reason", "pod is out of time"))
+					err = s.releaseSingleIPAndRemoveWEPFinalizer(logutils.IntoContext(ctx, wrappedLog), pool.Name, poolIP, poolIPAllocation)
+					if nil != err {
+						wrappedLog.Error(err.Error())
+						continue
+					}
+				} else {
+					// otherwise, flush the PodEntry database and let tracePodWorker to solve it if the current controller is elected master.
+					if s.leader.IsElected() {
+						err = s.PodDB.ApplyPodEntry(podEntry)
+						if nil != err {
+							scanAllLogger.Error(err.Error())
+							continue
+						}
+
+						scanAllLogger.With(zap.String("tracing-reason", string(podEntry.PodTracingReason))).
+							Sugar().Infof("update podEntry '%s/%s' successfully", poolIPAllocation.Namespace, poolIPAllocation.Pod)
+					}
+				}
+			} else {
+				endpoint, err := s.wepMgr.GetEndpointByName(ctx, podYaml.Namespace, podYaml.Name, constant.UseCache)
+				if err != nil {
+					scanAllLogger.Sugar().Errorf("failed to get Endpoint '%s/%s', error: %v", podYaml.Namespace, podYaml.Name, err)
+					continue
+				}
+
+				// case: The pod in IPPool's ip-allocationDetail is also exist in k8s, but the IPPool IP corresponding allocation pod UID is different with Endpoint pod UID
+				if endpoint.Status.Current.UID != poolIPAllocation.UID {
+					wrappedLog := scanAllLogger.With(zap.String("gc-reason", "IPPoolAllocation pod UID is different with Endpoint pod UID"))
+					// release IP but no need to clean up SpiderEndpoint object
+					err = s.ippoolMgr.ReleaseIP(ctx, pool.Name, []types.IPAndUID{{
+						IP:  poolIP,
+						UID: poolIPAllocation.UID},
+					})
+					if nil != err {
+						wrappedLog.Sugar().Errorf("failed to release ip '%s', error: '%v'", poolIP, err)
+						continue
+					}
+
+					wrappedLog.Sugar().Infof("release ip '%s' successfully!", poolIP)
+				} else {
+					// case: The pod in IPPool's ip-allocationDetail is also exist in k8s,
+					// and the IPPool IP corresponding allocation pod UID is same with Endpoint pod UID, but the IPPool IP isn't belong to the Endpoint IPs
+					wrappedLog := scanAllLogger.With(zap.String("gc-reason", "same pod UID but IPPoolAllocation IP is different with Endpoint IP"))
+					isBadIP := true
+					for _, endpointIP := range endpoint.Status.Current.IPs {
+						if *pool.Spec.IPVersion == constant.IPv4 {
+							if endpointIP.IPv4 != nil && strings.Split(*endpointIP.IPv4, "/")[0] == poolIP {
+								isBadIP = false
+							}
+						} else {
+							if endpointIP.IPv6 != nil && strings.Split(*endpointIP.IPv6, "/")[0] == poolIP {
+								isBadIP = false
+							}
+						}
+					}
+					if isBadIP {
+						// release IP but no need to clean up SpiderEndpoint object
+						err = s.ippoolMgr.ReleaseIP(ctx, pool.Name, []types.IPAndUID{{
+							IP:  poolIP,
+							UID: poolIPAllocation.UID},
+						})
+						if nil != err {
+							wrappedLog.Sugar().Errorf("failed to release ip '%s', error: '%v'", poolIP, err)
+							continue
+						}
+						wrappedLog.Sugar().Infof("release ip '%s' successfully!", poolIP)
+					}
+				}
+			}
+		}
+		logger.Sugar().Debugf("task checking IPPool '%s' is completed", pool.Name)
+	}
 }
 
 // releaseSingleIPAndRemoveWEPFinalizer serves for handleTerminatingPod to gc singleIP and remove wep finalizer
 func (s *SpiderGC) releaseSingleIPAndRemoveWEPFinalizer(ctx context.Context, poolName, poolIP string, poolIPAllocation spiderpoolv1.PoolIPAllocation) error {
-	// log := logutils.FromContext(ctx)
-
-	// singleIP := []types.IPAndCID{{IP: poolIP, ContainerID: poolIPAllocation.UID}}
-	// err := s.ippoolMgr.ReleaseIP(ctx, poolName, singleIP)
-	// if nil != err {
-	// 	metrics.IPGCFailureCounts.Add(ctx, 1)
-	// 	return fmt.Errorf("failed to release IP '%s', error: '%v'", poolIP, err)
-	// }
-
-	// metrics.IPGCTotalCounts.Add(ctx, 1)
-	// log.Sugar().Infof("release ip '%s' successfully", poolIP)
-
-	// err = s.wepMgr.RemoveFinalizer(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod)
-	// if nil != err {
-	// 	if apierrors.IsNotFound(err) {
-	// 		log.Sugar().Debugf("SpiderEndpoint '%s/%s' is already cleaned up", poolIPAllocation.Namespace, poolIPAllocation.Pod)
-	// 		return nil
-	// 	}
-	// 	return fmt.Errorf("failed to remove SpiderEndpoint '%s/%s' finalizer, error: '%v'", poolIPAllocation.Namespace, poolIPAllocation.Pod, err)
-	// }
-
-	// log.Sugar().Infof("remove SpiderEndpoint '%s/%s' finalizer successfully", poolIPAllocation.Namespace, poolIPAllocation.Pod)
+	log := logutils.FromContext(ctx)
+
+	singleIP := []types.IPAndUID{{IP: poolIP, UID: poolIPAllocation.UID}}
+	err := s.ippoolMgr.ReleaseIP(ctx, poolName, singleIP)
+	if nil != err {
+		metric.IPGCFailureCounts.Add(ctx, 1)
+		return fmt.Errorf("failed to release IP '%s', error: '%v'", poolIP, err)
+	}
+
+	metric.IPGCTotalCounts.Add(ctx, 1)
+	log.Sugar().Infof("release ip '%s' successfully", poolIP)
+
+	err = s.wepMgr.RemoveFinalizer(ctx, poolIPAllocation.Namespace, poolIPAllocation.Pod)
+	if nil != err {
+		if apierrors.IsNotFound(err) {
+			log.Sugar().Debugf("SpiderEndpoint '%s/%s' is already cleaned up", poolIPAllocation.Namespace, poolIPAllocation.Pod)
+			return nil
+		}
+		return fmt.Errorf("failed to remove SpiderEndpoint '%s/%s' finalizer, error: '%v'", poolIPAllocation.Namespace, poolIPAllocation.Pod, err)
+	}
+
+	log.Sugar().Infof("remove SpiderEndpoint '%s/%s' finalizer successfully", poolIPAllocation.Namespace, poolIPAllocation.Pod)
 	return nil
 }
diff --git a/pkg/gcmanager/tracePod_worker.go b/pkg/gcmanager/tracePod_worker.go
index 88c7486d7..449a87fda 100644
--- a/pkg/gcmanager/tracePod_worker.go
+++ b/pkg/gcmanager/tracePod_worker.go
@@ -8,6 +8,11 @@ import (
 	"time"
 
 	"go.uber.org/zap"
+	apierrors "k8s.io/apimachinery/pkg/api/errors"
+
+	"github.com/spidernet-io/spiderpool/pkg/constant"
+	"github.com/spidernet-io/spiderpool/pkg/metric"
+	"github.com/spidernet-io/spiderpool/pkg/utils/convert"
 )
 
 // tracePodWorker will circle traverse PodEntry database
@@ -61,65 +66,62 @@ func (s *SpiderGC) releaseIPPoolIPExecutor(ctx context.Context, workerIndex int)
 	loggerReleaseIP := logger.With(zap.Any("IPPoolIP_Worker", workerIndex))
 	loggerReleaseIP.Info("Starting running 'releaseIPPoolIPExecutor'")
 
-	// for {
-	// 	select {
-	// 	case podCache := <-s.gcIPPoolIPSignal:
-	// 		endpoint, err := s.wepMgr.GetEndpointByName(ctx, podCache.Namespace, podCache.PodName)
-	// 		if nil != err {
-	// 			if apierrors.IsNotFound(err) {
-	// 				loggerReleaseIP.Sugar().Infof("SpiderEndpoint '%s/%s' not found, maybe already cleaned by ScanAll", podCache.Namespace, podCache.PodName)
-	// 				continue
-	// 			}
-
-	// 			loggerReleaseIP.Sugar().Errorf("failed to get SpiderEndpoint '%s/%s', error: %v", podCache.Namespace, podCache.PodName, err)
-	// 			continue
-	// 		}
-
-	// 		// we need to gather the pod corresponding SpiderEndpoint to get the used history IPs.
-	// 		podUsedIPs := workloadendpointmanager.ListAllHistoricalIPs(endpoint)
-
-	// 		// release pod used history IPs
-	// 		for poolName, ips := range podUsedIPs {
-	// 			loggerReleaseIP.Sugar().Infof("pod '%s/%s used IPs '%+v' from pool '%s', begin to release",
-	// 				podCache.Namespace, podCache.PodName, ips, poolName)
-
-	// 			err = s.ippoolMgr.ReleaseIP(ctx, poolName, ips)
-	// 			if nil != err {
-	// 				metrics.IPGCFailureCounts.Add(ctx, 1)
-	// 				loggerReleaseIP.Sugar().Errorf("failed to release pool '%s' IPs '%+v' in wep '%s/%s', error: %v",
-	// 					poolName, ips, podCache.Namespace, podCache.PodName, err)
-	// 				continue
-	// 			}
-
-	// 			// metric
-	// 			metrics.IPGCTotalCounts.Add(ctx, 1)
-	// 		}
-
-	// 		loggerReleaseIP.Sugar().Infof("release IPPoolIP task '%+v' successfully", *podCache)
-
-	// 		// delete StatefulSet wep (other controller wep has OwnerReference, its lifecycle is same with pod)
-	// 		if endpoint.Status.OwnerControllerType == constant.KindStatefulSet {
-	// 			err = s.wepMgr.DeleteEndpoint(ctx, endpoint)
-	// 			if nil != err {
-	// 				loggerReleaseIP.Sugar().Errorf("failed to delete StatefulSet wep '%s/%s', error: '%v'",
-	// 					podCache.Namespace, podCache.PodName, err)
-	// 				continue
-	// 			}
-	// 		}
-
-	// 		err = s.wepMgr.RemoveFinalizer(ctx, podCache.Namespace, podCache.PodName)
-	// 		if nil != err {
-	// 			loggerReleaseIP.Sugar().Errorf("failed to remove wep '%s/%s' finalizer, error: '%v'",
-	// 				podCache.Namespace, podCache.PodName, err)
-	// 			continue
-	// 		}
-
-	// 		loggerReleaseIP.Sugar().Infof("remove wep '%s/%s' finalizer '%s' successfully",
-	// 			podCache.Namespace, podCache.PodName, constant.SpiderFinalizer)
-
-	// 	case <-ctx.Done():
-	// 		loggerReleaseIP.Info("receive ctx done, stop running releaseIPPoolIPExecutor")
-	// 		return
-	// 	}
-	// }
+	for {
+		select {
+		case podCache := <-s.gcIPPoolIPSignal:
+			endpoint, err := s.wepMgr.GetEndpointByName(ctx, podCache.Namespace, podCache.PodName, constant.UseCache)
+			if nil != err {
+				if apierrors.IsNotFound(err) {
+					loggerReleaseIP.Sugar().Infof("SpiderEndpoint '%s/%s' not found, maybe already cleaned by ScanAll", podCache.Namespace, podCache.PodName)
+					continue
+				}
+
+				loggerReleaseIP.Sugar().Errorf("failed to get SpiderEndpoint '%s/%s', error: %v", podCache.Namespace, podCache.PodName, err)
+				continue
+			}
+
+			// we need to gather the pod corresponding SpiderEndpoint allocation data to get the used history IPs.
+			podUsedIPs := convert.GroupIPAllocationDetails(endpoint.Status.Current.UID, endpoint.Status.Current.IPs)
+			// release pod used history IPs
+			for poolName, ips := range podUsedIPs {
+				loggerReleaseIP.Sugar().Infof("pod '%s/%s used IPs '%+v' from pool '%s', begin to release",
+					podCache.Namespace, podCache.PodName, ips, poolName)
+
+				err = s.ippoolMgr.ReleaseIP(ctx, poolName, ips)
+				if nil != err {
+					metric.IPGCFailureCounts.Add(ctx, 1)
+					loggerReleaseIP.Sugar().Errorf("failed to release pool '%s' IPs '%+v' in SpiderEndpoint '%s/%s', error: %v",
+						poolName, ips, podCache.Namespace, podCache.PodName, err)
+					continue
+				}
+				metric.IPGCTotalCounts.Add(ctx, 1)
+			}
+
+			loggerReleaseIP.Sugar().Infof("release IPPoolIP task '%+v' successfully", *podCache)
+
+			// delete StatefulSet wep (other controller wep has OwnerReference, its lifecycle is same with pod)
+			if endpoint.Status.OwnerControllerType == constant.KindStatefulSet && endpoint.DeletionTimestamp == nil {
+				err = s.wepMgr.DeleteEndpoint(ctx, endpoint)
+				if nil != err {
+					loggerReleaseIP.Sugar().Errorf("failed to delete StatefulSet wep '%s/%s', error: '%v'",
+						podCache.Namespace, podCache.PodName, err)
+					continue
+				}
+			}
+
+			err = s.wepMgr.RemoveFinalizer(ctx, podCache.Namespace, podCache.PodName)
+			if nil != err {
+				loggerReleaseIP.Sugar().Errorf("failed to remove wep '%s/%s' finalizer, error: '%v'",
+					podCache.Namespace, podCache.PodName, err)
+				continue
+			}
+
+			loggerReleaseIP.Sugar().Infof("remove wep '%s/%s' finalizer '%s' successfully",
+				podCache.Namespace, podCache.PodName, constant.SpiderFinalizer)
+
+		case <-ctx.Done():
+			loggerReleaseIP.Info("receive ctx done, stop running releaseIPPoolIPExecutor")
+			return
+		}
+	}
 }
diff --git a/pkg/ipam/release.go b/pkg/ipam/release.go
index b7734faf8..d61cd1955 100644
--- a/pkg/ipam/release.go
+++ b/pkg/ipam/release.go
@@ -89,10 +89,14 @@ func (i *ipam) Release(ctx context.Context, delArgs *models.IpamDelArgs) error {
 func (i *ipam) releaseForAllNICs(ctx context.Context, uid, nic string, endpoint *spiderpoolv1.SpiderEndpoint) error {
 	logger := logutils.FromContext(ctx)
 
-	// Check whether an STS needs to release its currently allocated IP addresses.
+	// Check whether an StatefulSet needs to release its currently allocated IP addresses.
 	// It is discussed in https://github.com/spidernet-io/spiderpool/issues/1045
 	if i.config.EnableStatefulSet && endpoint.Status.OwnerControllerType == constant.KindStatefulSet {
-		valid := i.stsManager.IsValidStatefulSetPod(ctx, endpoint.Namespace, endpoint.Name)
+		valid, err := i.stsManager.IsValidStatefulSetPod(ctx, endpoint.Namespace, endpoint.Name, endpoint.Status.OwnerControllerType)
+		if nil != err {
+			return fmt.Errorf("failed to check pod %s/%s whether is a valid StatefulSet pod: %v", endpoint.Namespace, endpoint.Name, err)
+		}
+
 		if valid {
 			logger.Info("There is no need to release the IP allocation of StatefulSet")
 			return nil
diff --git a/pkg/ippoolmanager/ippool_validate.go b/pkg/ippoolmanager/ippool_validate.go
index 7adb9470a..a9165ecd4 100644
--- a/pkg/ippoolmanager/ippool_validate.go
+++ b/pkg/ippoolmanager/ippool_validate.go
@@ -25,7 +25,6 @@ var (
 	excludeIPsField *field.Path = field.NewPath("spec").Child("excludeIPs")
 	gatewayField    *field.Path = field.NewPath("spec").Child("gateway")
 	routesField     *field.Path = field.NewPath("spec").Child("routes")
-	defaultField    *field.Path = field.NewPath("spec").Child("default")
 )
 
 func (iw *IPPoolWebhook) validateCreateIPPool(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) field.ErrorList {
@@ -94,9 +93,6 @@ func validateIPPoolShouldNotBeChanged(oldIPPool, newIPPool *spiderpoolv1.SpiderI
 }
 
 func (iw *IPPoolWebhook) validateIPPoolSpec(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) *field.Error {
-	if err := iw.validateIPPoolDefault(ctx, ipPool); err != nil {
-		return err
-	}
 	if err := iw.validateIPPoolAvailableIPs(ctx, ipPool); err != nil {
 		return err
 	}
@@ -218,34 +214,6 @@ func (iw *IPPoolWebhook) validateIPPoolCIDR(ctx context.Context, ipPool *spiderp
 	return nil
 }
 
-func (iw *IPPoolWebhook) validateIPPoolDefault(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) *field.Error {
-	if ipPool.Spec.Default == nil || !*ipPool.Spec.Default {
-		return nil
-	}
-
-	var ipPoolList spiderpoolv1.SpiderIPPoolList
-	if err := iw.Client.List(
-		ctx,
-		&ipPoolList,
-		client.MatchingFields{"spec.default": strconv.FormatBool(true)},
-	); err != nil {
-		return field.InternalError(defaultField, fmt.Errorf("failed to list default IPPools: %v", err))
-	}
-
-	for _, dp := range ipPoolList.Items {
-		if *dp.Spec.IPVersion == *ipPool.Spec.IPVersion {
-			if dp.Name != ipPool.Name {
-				return field.Forbidden(
-					defaultField,
-					fmt.Sprintf("IPPool %s has been set as the default IPPool, and there is only one default IPPool in the cluster", dp.Name),
-				)
-			}
-		}
-	}
-
-	return nil
-}
-
 func (iw *IPPoolWebhook) validateIPPoolAvailableIPs(ctx context.Context, ipPool *spiderpoolv1.SpiderIPPool) *field.Error {
 	if err := iw.validateIPPoolIPs(*ipPool.Spec.IPVersion, ipPool.Spec.Subnet, ipPool.Spec.IPs); err != nil {
 		return err
diff --git a/pkg/statefulsetmanager/sts_manager.go b/pkg/statefulsetmanager/sts_manager.go
index 67d39ee20..735723d71 100644
--- a/pkg/statefulsetmanager/sts_manager.go
+++ b/pkg/statefulsetmanager/sts_manager.go
@@ -8,7 +8,6 @@ import (
 	"fmt"
 
 	appsv1 "k8s.io/api/apps/v1"
-	apierrors "k8s.io/apimachinery/pkg/api/errors"
 	apitypes "k8s.io/apimachinery/pkg/types"
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
@@ -18,7 +17,7 @@ import (
 type StatefulSetManager interface {
 	GetStatefulSetByName(ctx context.Context, namespace, name string, cached bool) (*appsv1.StatefulSet, error)
 	ListStatefulSets(ctx context.Context, cached bool, opts ...client.ListOption) (*appsv1.StatefulSetList, error)
-	IsValidStatefulSetPod(ctx context.Context, namespace, podName string) bool
+	IsValidStatefulSetPod(ctx context.Context, namespace, podName, podControllerType string) (bool, error)
 }
 
 type statefulSetManager struct {
@@ -71,22 +70,26 @@ func (sm *statefulSetManager) ListStatefulSets(ctx context.Context, cached bool,
 // IsValidStatefulSetPod only serves for StatefulSet pod, it will check the pod whether need to be cleaned up with the given params podNS, podName.
 // Once the pod's controller StatefulSet was deleted, the pod's corresponding IPPool IP and Endpoint need to be cleaned up.
 // Or the pod's controller StatefulSet decreased its replicas and the pod's index is out of replicas, it needs to be cleaned up too.
-func (sm *statefulSetManager) IsValidStatefulSetPod(ctx context.Context, namespace, podName string) bool {
+func (sm *statefulSetManager) IsValidStatefulSetPod(ctx context.Context, namespace, podName, podControllerType string) (bool, error) {
+	if podControllerType != constant.KindStatefulSet {
+		return false, fmt.Errorf("pod '%s/%s' is controlled by '%s' instead of StatefulSet", namespace, podName, podControllerType)
+	}
+
 	stsName, replicas, found := getStatefulSetNameAndOrdinal(podName)
 	if !found {
-		return false
+		return false, fmt.Errorf("failed to parse the name and replica of its StatefulSet controller from the name of Pod '%s/%s'", namespace, podName)
 	}
 
 	sts, err := sm.GetStatefulSetByName(ctx, namespace, stsName, constant.IgnoreCache)
 	if err != nil {
-		return !apierrors.IsNotFound(err)
+		return false, client.IgnoreNotFound(err)
 	}
 
 	// The Pod controlled by StatefulSet is created or re-created.
 	if replicas <= int(*sts.Spec.Replicas)-1 {
-		return true
+		return true, nil
 	}
 
 	// StatefulSet scaled down.
-	return false
+	return false, nil
 }
diff --git a/pkg/subnetmanager/subnet_validate.go b/pkg/subnetmanager/subnet_validate.go
index 1555eceec..1851e7979 100644
--- a/pkg/subnetmanager/subnet_validate.go
+++ b/pkg/subnetmanager/subnet_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"
@@ -25,7 +24,6 @@ var (
 	excludeIPsField        *field.Path = field.NewPath("spec").Child("excludeIPs")
 	gatewayField           *field.Path = field.NewPath("spec").Child("gateway")
 	routesField            *field.Path = field.NewPath("spec").Child("routes")
-	defaultField           *field.Path = field.NewPath("spec").Child("default")
 	controlledIPPoolsField *field.Path = field.NewPath("status").Child("controlledIPPools")
 )
 
@@ -95,9 +93,6 @@ func validateSubnetShouldNotBeChanged(oldSubnet, newSubnet *spiderpoolv1.SpiderS
 }
 
 func (sw *SubnetWebhook) validateSubnetSpec(ctx context.Context, subnet *spiderpoolv1.SpiderSubnet) *field.Error {
-	if err := sw.validateSubnetDefault(ctx, subnet); err != nil {
-		return err
-	}
 	if err := validateSubnetIPs(*subnet.Spec.IPVersion, subnet.Spec.Subnet, subnet.Spec.IPs); err != nil {
 		return err
 	}
@@ -210,34 +205,6 @@ func (sw *SubnetWebhook) validateSubnetCIDR(ctx context.Context, subnet *spiderp
 	return nil
 }
 
-func (sw *SubnetWebhook) validateSubnetDefault(ctx context.Context, subnet *spiderpoolv1.SpiderSubnet) *field.Error {
-	if subnet.Spec.Default == nil || !*subnet.Spec.Default {
-		return nil
-	}
-
-	var subnetList spiderpoolv1.SpiderSubnetList
-	if err := sw.Client.List(
-		ctx,
-		&subnetList,
-		client.MatchingFields{"spec.default": strconv.FormatBool(true)},
-	); err != nil {
-		return field.InternalError(defaultField, fmt.Errorf("failed to list default Subnets: %v", err))
-	}
-
-	for _, ds := range subnetList.Items {
-		if *ds.Spec.IPVersion == *subnet.Spec.IPVersion {
-			if ds.Name != subnet.Name {
-				return field.Forbidden(
-					defaultField,
-					fmt.Sprintf("Subnet %s has been set as the default Subnet, and there is only one default Subnet in the cluster", ds.Name),
-				)
-			}
-		}
-	}
-
-	return nil
-}
-
 func validateSubnetIPs(version types.IPVersion, subnet string, ips []string) *field.Error {
 	for i, r := range ips {
 		if err := ippoolmanager.ValidateContainsIPRange(ipsField.Index(i), version, subnet, r); err != nil {


Test patch:
diff --git a/pkg/ippoolmanager/ippool_webhook_test.go b/pkg/ippoolmanager/ippool_webhook_test.go
index ac40d8908..2aeed0257 100644
--- a/pkg/ippoolmanager/ippool_webhook_test.go
+++ b/pkg/ippoolmanager/ippool_webhook_test.go
@@ -46,8 +46,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 	})
 
 	Describe("Test IPPoolWebhook's method", func() {
-		var ctx context.Context
-
 		var count uint64
 		var subnetName string
 		var subnetT *spiderpoolv1.SpiderSubnet
@@ -60,8 +58,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			ipPoolWebhook.EnableIPv6 = true
 			ipPoolWebhook.EnableSpiderSubnet = false
 
-			ctx = context.TODO()
-
 			atomic.AddUint64(&count, 1)
 			subnetName = fmt.Sprintf("subnet-%v", count)
 			subnetT = &spiderpoolv1.SpiderSubnet{
@@ -111,6 +107,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				PropagationPolicy:  &policy,
 			}
 
+			ctx := context.TODO()
 			err := fakeClient.Delete(ctx, ipPoolT, deleteOption)
 			Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred())
 
@@ -159,6 +156,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				now := metav1.Now()
 				ipPoolT.SetDeletionTimestamp(&now)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 			})
@@ -166,6 +164,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			It("adds finalizer", func() {
 				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -177,6 +176,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), 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())
 
@@ -189,6 +189,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				subnet := "172.18.40.0/24"
 				ipPoolT.Spec.Subnet = subnet
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -205,6 +206,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				ipPoolWebhook.EnableSpiderSubnet = true
 				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -234,6 +236,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err = fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -271,6 +274,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err = fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -305,6 +309,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err = fakeClient.Create(ctx, subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -326,6 +331,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			It("failed to set 'spec.ipVersion' due to the invalid 'spec.subnet'", func() {
 				ipPoolT.Spec.Subnet = constant.InvalidCIDR
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.IPVersion).To(BeNil())
@@ -334,6 +340,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			It("sets 'spec.ipVersion' to 4", func() {
 				ipPoolT.Spec.Subnet = "172.18.40.0/24"
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(*ipPoolT.Spec.IPVersion).To(Equal(constant.IPv4))
@@ -342,6 +349,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 			It("sets 'spec.ipVersion' to 6", func() {
 				ipPoolT.Spec.Subnet = "abcd:1234::/120"
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(*ipPoolT.Spec.IPVersion).To(Equal(constant.IPv6))
@@ -358,6 +366,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.IPs).To(Equal(
@@ -381,6 +390,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.IPs).To(Equal(
@@ -403,6 +413,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.IPs).To(Equal(
@@ -423,6 +434,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.IPs).To(Equal(
@@ -444,6 +456,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.ExcludeIPs).To(Equal(
@@ -467,6 +480,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.ExcludeIPs).To(Equal(
@@ -489,6 +503,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.ExcludeIPs).To(Equal(
@@ -509,6 +524,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.Default(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(ipPoolT.Spec.ExcludeIPs).To(Equal(
@@ -531,6 +547,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -545,6 +562,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -560,6 +578,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -575,6 +594,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -591,6 +611,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -608,6 +629,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -622,6 +644,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := tracker.Add(ipPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -634,7 +657,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.41.1-172.18.41.2")
 
-					err := tracker.Add(existIPPoolT)
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
 					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
@@ -650,6 +674,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = constant.InvalidCIDR
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.41.1-172.18.41.2")
 
+					ctx := context.TODO()
 					err := tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -671,6 +696,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = "172.18.40.0/25"
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.40.40")
 
+					ctx := context.TODO()
 					err := tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -688,48 +714,13 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				})
 			})
 
-			When("Validating 'spec.default'", func() {
-				It("creates non-default IPv4 IPPool", func() {
-					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					ipPoolT.Spec.Subnet = "172.18.40.0/24"
-					ipPoolT.Spec.Default = pointer.Bool(false)
-
-					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-
-				It("creates default IPv4 IPPool, but there is already one in the cluster", func() {
-					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
-					existIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err := fakeClient.Create(ctx, existIPPoolT)
-					Expect(err).NotTo(HaveOccurred())
-
-					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					ipPoolT.Spec.Subnet = "172.18.40.0/24"
-					ipPoolT.Spec.Default = pointer.Bool(true)
-
-					err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
-					Expect(apierrors.IsInvalid(err)).To(BeTrue())
-				})
-
-				It("creates default IPv4 IPPool", func() {
-					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					ipPoolT.Spec.Subnet = "172.18.40.0/24"
-					ipPoolT.Spec.Default = pointer.Bool(true)
-
-					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-			})
-
 			When("Validating 'spec.ips'", func() {
 				It("inputs 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, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -744,6 +735,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -752,6 +744,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), 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(err).NotTo(HaveOccurred())
 				})
@@ -768,6 +761,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = subnet
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err = tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -796,6 +790,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = subnet
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.40.10")
 
+					ctx := context.TODO()
 					err = tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -825,6 +820,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					)
 					ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -840,6 +836,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					)
 					ipPoolT.Spec.ExcludeIPs = append(ipPoolT.Spec.ExcludeIPs, "172.18.41.10")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -857,6 +854,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					)
 					ipPoolT.Spec.Gateway = pointer.String(constant.InvalidIP)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -872,6 +870,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					)
 					ipPoolT.Spec.Gateway = pointer.String("172.18.41.1")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -894,6 +893,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -914,6 +914,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -934,6 +935,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -954,6 +956,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -981,6 +984,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
+					ctx := context.TODO()
 					err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -996,7 +1000,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
-					err := tracker.Add(subnetT)
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
 					Expect(err).NotTo(HaveOccurred())
 
 					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
@@ -1020,7 +1025,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						}...,
 					)
 
-					err := tracker.Add(subnetT)
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
 					Expect(err).NotTo(HaveOccurred())
 
 					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
@@ -1052,6 +1058,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := tracker.Add(subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -1075,7 +1082,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						Gw:  "172.18.40.40",
 					},
 				)
-				ipPoolT.Spec.Default = pointer.Bool(true)
 
 				err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
@@ -1093,6 +1099,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := tracker.Add(subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -1116,7 +1123,6 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						Gw:  "abcd:1234::28",
 					},
 				)
-				ipPoolT.Spec.Default = pointer.Bool(true)
 
 				err = ipPoolWebhook.ValidateCreate(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
@@ -1138,6 +1144,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPVersion = nil
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1155,6 +1162,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv6)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1168,6 +1176,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "172.18.40.10")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1181,6 +1190,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "adbc:1234::a")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1200,44 +1210,12 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.Subnet = "172.18.40.0/25"
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
 			})
 
-			When("Validating 'spec.default'", func() {
-				It("set default IPv4 IPPool, but there is already one in the cluster", func() {
-					existIPPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					existIPPoolT.Spec.Subnet = "172.18.40.0/24"
-					existIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err := fakeClient.Create(ctx, existIPPoolT)
-					Expect(err).NotTo(HaveOccurred())
-
-					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					ipPoolT.Spec.Subnet = "172.18.40.0/24"
-					ipPoolT.Spec.Default = pointer.Bool(false)
-
-					newIPPoolT := ipPoolT.DeepCopy()
-					newIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
-					Expect(apierrors.IsInvalid(err)).To(BeTrue())
-				})
-
-				It("set default IPv4 IPPool", func() {
-					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					ipPoolT.Spec.Subnet = "172.18.40.0/24"
-					ipPoolT.Spec.Default = pointer.Bool(false)
-
-					newIPPoolT := ipPoolT.DeepCopy()
-					newIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-			})
-
 			When("Validating 'spec.ips'", func() {
 				It("appends invalid IP range to 'spec.ips'", func() {
 					ipPoolT.Spec.IPVersion = pointer.Int64(constant.IPv4)
@@ -1252,6 +1230,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1264,6 +1243,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "172.18.41.10")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1276,6 +1256,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = []string{}
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 				})
@@ -1292,6 +1273,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = subnet
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err = tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -1318,6 +1300,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					existIPPoolT.Spec.Subnet = subnet
 					existIPPoolT.Spec.IPs = append(existIPPoolT.Spec.IPs, "172.18.40.10")
 
+					ctx := context.TODO()
 					err = tracker.Add(existIPPoolT)
 					Expect(err).NotTo(HaveOccurred())
 
@@ -1347,6 +1330,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.ExcludeIPs = append(newIPPoolT.Spec.ExcludeIPs, constant.InvalidIPRange)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1364,6 +1348,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.ExcludeIPs = append(newIPPoolT.Spec.ExcludeIPs, "172.18.41.10")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1384,6 +1369,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.Gateway = pointer.String(constant.InvalidIP)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1402,6 +1388,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.Gateway = pointer.String("172.18.41.1")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1426,6 +1413,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1448,6 +1436,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1470,6 +1459,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 						},
 					)
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1502,6 +1492,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = newIPPoolT.Spec.IPs[:1]
 
+					ctx := context.TODO()
 					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1520,6 +1511,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "172.18.40.10")
 
+					ctx := context.TODO()
 					err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1545,6 +1537,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					newIPPoolT := ipPoolT.DeepCopy()
 					newIPPoolT.Spec.IPs = append(newIPPoolT.Spec.IPs, "172.18.40.10")
 
+					ctx := context.TODO()
 					err = ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 					Expect(apierrors.IsInvalid(err)).To(BeTrue())
 				})
@@ -1555,7 +1548,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					subnetT.Spec.Subnet = "172.18.40.0/24"
 					subnetT.Spec.IPs = append(subnetT.Spec.IPs, "172.18.40.1-172.18.40.2")
 
-					err := tracker.Add(subnetT)
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
 					Expect(err).NotTo(HaveOccurred())
 
 					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
@@ -1578,7 +1572,8 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					subnetT.Spec.Subnet = "172.18.40.0/24"
 					subnetT.Spec.IPs = append(subnetT.Spec.IPs, "172.18.40.1-172.18.40.2")
 
-					err := tracker.Add(subnetT)
+					ctx := context.TODO()
+					err := fakeClient.Create(ctx, subnetT)
 					Expect(err).NotTo(HaveOccurred())
 
 					err = controllerutil.SetControllerReference(subnetT, ipPoolT, scheme)
@@ -1605,6 +1600,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 				newIPPoolT := ipPoolT.DeepCopy()
 				controllerutil.RemoveFinalizer(newIPPoolT, constant.SpiderFinalizer)
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 				Expect(err).NotTo(HaveOccurred())
 			})
@@ -1617,6 +1613,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 				newIPPoolT := ipPoolT.DeepCopy()
 
+				ctx := context.TODO()
 				err := ipPoolWebhook.ValidateUpdate(ctx, ipPoolT, newIPPoolT)
 				Expect(apierrors.IsForbidden(err)).To(BeTrue())
 			})
@@ -1633,6 +1630,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := tracker.Add(subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -1671,6 +1669,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 					}...,
 				)
 
+				ctx := context.TODO()
 				err := tracker.Add(subnetT)
 				Expect(err).NotTo(HaveOccurred())
 
@@ -1700,6 +1699,7 @@ var _ = Describe("IPPoolWebhook", Label("ippool_webhook_test"), func() {
 
 		Describe("ValidateDelete", func() {
 			It("passes", func() {
+				ctx := context.TODO()
 				err := ipPoolWebhook.ValidateDelete(ctx, ipPoolT)
 				Expect(err).NotTo(HaveOccurred())
 			})
diff --git a/pkg/statefulsetmanager/sts_manager_test.go b/pkg/statefulsetmanager/sts_manager_test.go
index d19c79891..42c26e675 100644
--- a/pkg/statefulsetmanager/sts_manager_test.go
+++ b/pkg/statefulsetmanager/sts_manager_test.go
@@ -226,7 +226,8 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 
 		Describe("IsValidStatefulSetPod", func() {
 			It("is not a Pod of StatefulSet", func() {
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, "invalid")
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, namespace, "orphan-pod", constant.KindPod)
+				Expect(err).To(HaveOccurred())
 				Expect(valid).To(BeFalse())
 			})
 
@@ -234,12 +235,14 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 				patches := gomonkey.ApplyFuncReturn(strconv.ParseInt, int64(0), constant.ErrUnknown)
 				defer patches.Reset()
 
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0))
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0), constant.KindStatefulSet)
+				Expect(err).To(HaveOccurred())
 				Expect(valid).To(BeFalse())
 			})
 
 			It("is a valid Pod controlled by StatefulSet, but the StatefulSet no longer exists", func() {
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0))
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0), constant.KindStatefulSet)
+				Expect(err).NotTo(HaveOccurred())
 				Expect(valid).To(BeFalse())
 			})
 
@@ -247,8 +250,9 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 				patches := gomonkey.ApplyMethodReturn(fakeAPIReader, "Get", constant.ErrUnknown)
 				defer patches.Reset()
 
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0))
-				Expect(valid).To(BeTrue())
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, 0), constant.KindStatefulSet)
+				Expect(err).To(HaveOccurred())
+				Expect(valid).To(BeFalse())
 			})
 
 			It("used to be a Pod controlled by StatefulSet, but the StatefulSet scaled down", func() {
@@ -258,7 +262,8 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 				err := tracker.Add(stsT)
 				Expect(err).NotTo(HaveOccurred())
 
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, replicas))
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, replicas), constant.KindStatefulSet)
+				Expect(err).NotTo(HaveOccurred())
 				Expect(valid).To(BeFalse())
 			})
 
@@ -269,10 +274,10 @@ var _ = Describe("StatefulSetManager", Label("sts_manager_test"), func() {
 				err := tracker.Add(stsT)
 				Expect(err).NotTo(HaveOccurred())
 
-				valid := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, replicas-1))
+				valid, err := stsManager.IsValidStatefulSetPod(ctx, stsT.Namespace, fmt.Sprintf("%s-%d", stsName, replicas-1), constant.KindStatefulSet)
+				Expect(err).NotTo(HaveOccurred())
 				Expect(valid).To(BeTrue())
 			})
-
 		})
 	})
 })
diff --git a/pkg/subnetmanager/subnet_webhook_test.go b/pkg/subnetmanager/subnet_webhook_test.go
index 43d5e8641..448b85956 100644
--- a/pkg/subnetmanager/subnet_webhook_test.go
+++ b/pkg/subnetmanager/subnet_webhook_test.go
@@ -517,42 +517,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 				})
 			})
 
-			When("Validating 'spec.default'", func() {
-				It("creates non-default IPv4 IPPool", func() {
-					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					subnetT.Spec.Subnet = "172.18.40.0/24"
-					subnetT.Spec.Default = pointer.Bool(false)
-
-					err := subnetWebhook.ValidateCreate(ctx, subnetT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-
-				It("creates default IPv4 IPPool, but there is already one in the cluster", func() {
-					existSubnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					existSubnetT.Spec.Subnet = "172.18.40.0/24"
-					existSubnetT.Spec.Default = pointer.Bool(true)
-
-					err := fakeClient.Create(ctx, existSubnetT)
-					Expect(err).NotTo(HaveOccurred())
-
-					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					subnetT.Spec.Subnet = "172.18.40.0/24"
-					subnetT.Spec.Default = pointer.Bool(true)
-
-					err = subnetWebhook.ValidateCreate(ctx, subnetT)
-					Expect(apierrors.IsInvalid(err)).To(BeTrue())
-				})
-
-				It("creates default IPv4 IPPool", func() {
-					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					subnetT.Spec.Subnet = "172.18.40.0/24"
-					subnetT.Spec.Default = pointer.Bool(true)
-
-					err := subnetWebhook.ValidateCreate(ctx, subnetT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-			})
-
 			When("Validating 'spec.ips'", func() {
 				It("inputs invalid 'spec.ips'", func() {
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
@@ -833,39 +797,6 @@ var _ = Describe("SubnetWebhook", Label("subnet_webhook_test"), func() {
 				})
 			})
 
-			When("Validating 'spec.default'", func() {
-				It("set default IPv4 IPPool, but there is already one in the cluster", func() {
-					existSubnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					existSubnetT.Spec.Subnet = "172.18.40.0/24"
-					existSubnetT.Spec.Default = pointer.Bool(true)
-
-					err := fakeClient.Create(ctx, existSubnetT)
-					Expect(err).NotTo(HaveOccurred())
-
-					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					subnetT.Spec.Subnet = "172.18.40.0/24"
-					subnetT.Spec.Default = pointer.Bool(false)
-
-					newIPPoolT := subnetT.DeepCopy()
-					newIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err = subnetWebhook.ValidateUpdate(ctx, subnetT, newIPPoolT)
-					Expect(apierrors.IsInvalid(err)).To(BeTrue())
-				})
-
-				It("set default IPv4 IPPool", func() {
-					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)
-					subnetT.Spec.Subnet = "172.18.40.0/24"
-					subnetT.Spec.Default = pointer.Bool(false)
-
-					newIPPoolT := subnetT.DeepCopy()
-					newIPPoolT.Spec.Default = pointer.Bool(true)
-
-					err := subnetWebhook.ValidateUpdate(ctx, subnetT, newIPPoolT)
-					Expect(err).NotTo(HaveOccurred())
-				})
-			})
-
 			When("Validating 'spec.ips'", func() {
 				It("appends invalid IP range to 'spec.ips'", func() {
 					subnetT.Spec.IPVersion = pointer.Int64(constant.IPv4)