Repository: spidernet-io/spiderpool
Pull request #1425 (2023-03-10 10:57:50)

fix: The IP allocation of Endpoint is incomplete in multi-NIC mode
Signed-off-by: iiiceoo <ziqian.xue@daocloud.io>


Patch:
diff --git a/charts/spiderpool/crds/spiderpool.spidernet.io_spiderendpoints.yaml b/charts/spiderpool/crds/spiderpool.spidernet.io_spiderendpoints.yaml
index 45cae75b1..1944f1b19 100644
--- a/charts/spiderpool/crds/spiderpool.spidernet.io_spiderendpoints.yaml
+++ b/charts/spiderpool/crds/spiderpool.spidernet.io_spiderendpoints.yaml
@@ -73,8 +73,6 @@ spec:
                 type: string
               current:
                 properties:
-                  containerID:
-                    type: string
                   ips:
                     items:
                       properties:
@@ -121,7 +119,6 @@ spec:
                   uid:
                     type: string
                 required:
-                - containerID
                 - ips
                 - node
                 - uid
diff --git a/pkg/ipam/allocate.go b/pkg/ipam/allocate.go
index 120bc3af2..58852adae 100644
--- a/pkg/ipam/allocate.go
+++ b/pkg/ipam/allocate.go
@@ -51,7 +51,6 @@ func (i *ipam) Allocate(ctx context.Context, addArgs *models.IpamAddArgs) (*mode
 	if client.IgnoreNotFound(err) != nil {
 		return nil, fmt.Errorf("failed to get Endpoint %s/%s: %v", pod.Namespace, pod.Name, err)
 	}
-
 	if endpoint != nil {
 		logger.Sugar().Debugf("Get Endpoint %s/%s", pod.Namespace, pod.Name)
 	} else {
@@ -59,8 +58,8 @@ func (i *ipam) Allocate(ctx context.Context, addArgs *models.IpamAddArgs) (*mode
 	}
 
 	if i.config.EnableStatefulSet && podTopController.Kind == constant.KindStatefulSet {
-		logger.Info("Retrieve the IP allocation of StatefulSet")
-		addResp, err := i.retrieveStsIPAllocation(ctx, *addArgs.ContainerID, pod, endpoint)
+		logger.Info("Try to retrieve the IP allocation of StatefulSet")
+		addResp, err := i.retrieveStsIPAllocation(ctx, *addArgs.IfName, pod, endpoint)
 		if err != nil {
 			return nil, fmt.Errorf("failed to retrieve the IP allocation of StatefulSet %s/%s: %w", podTopController.Namespace, podTopController.Name, err)
 		}
@@ -69,9 +68,9 @@ func (i *ipam) Allocate(ctx context.Context, addArgs *models.IpamAddArgs) (*mode
 		}
 	} else {
 		logger.Debug("Try to retrieve the existing IP allocation")
-		addResp, err := i.retrieveMultiNICIPAllocation(ctx, string(pod.UID), *addArgs.IfName, endpoint)
+		addResp, err := i.retrieveExistingIPAllocation(ctx, string(pod.UID), *addArgs.IfName, endpoint)
 		if err != nil {
-			return nil, fmt.Errorf("failed to retrieve the IP allocation: %w", err)
+			return nil, fmt.Errorf("failed to retrieve the existing IP allocation: %w", err)
 		}
 		if addResp != nil {
 			return addResp, nil
@@ -87,12 +86,13 @@ func (i *ipam) Allocate(ctx context.Context, addArgs *models.IpamAddArgs) (*mode
 	return addResp, nil
 }
 
-func (i *ipam) retrieveStsIPAllocation(ctx context.Context, containerID string, pod *corev1.Pod, endpoint *spiderpoolv1.SpiderEndpoint) (*models.IpamAddResponse, error) {
+func (i *ipam) retrieveStsIPAllocation(ctx context.Context, nic string, pod *corev1.Pod, endpoint *spiderpoolv1.SpiderEndpoint) (*models.IpamAddResponse, error) {
 	logger := logutils.FromContext(ctx)
 
-	// The first allocation.
-	if endpoint == nil {
-		logger.Debug("Endpoint not found, try to allocate IP in standard mode instead of retrieving")
+	allocation := workloadendpointmanager.RetrieveIPAllocation(string(pod.UID), nic, endpoint, true)
+	if allocation == nil {
+		// The first allocation or multi-NIC.
+		logger.Debug("IP allocation is not found, try to allocate IP in standard mode instead of retrieving")
 		return nil, nil
 	}
 
@@ -102,7 +102,7 @@ func (i *ipam) retrieveStsIPAllocation(ctx context.Context, containerID string,
 	}
 
 	logger.Info("Refresh the current IP allocation of the Endpoint")
-	if err := i.endpointManager.ReallocateCurrentIPAllocation(ctx, containerID, string(pod.UID), pod.Spec.NodeName, endpoint); err != nil {
+	if err := i.endpointManager.ReallocateCurrentIPAllocation(ctx, string(pod.UID), pod.Spec.NodeName, endpoint); err != nil {
 		return nil, fmt.Errorf("failed to update the current IP allocation of StatefulSet: %w", err)
 	}
 
@@ -161,10 +161,17 @@ func (i *ipam) reallocateIPPoolIPRecords(ctx context.Context, uid string, endpoi
 	return nil
 }
 
-func (i *ipam) retrieveMultiNICIPAllocation(ctx context.Context, uid, nic string, endpoint *spiderpoolv1.SpiderEndpoint) (*models.IpamAddResponse, error) {
+func (i *ipam) retrieveExistingIPAllocation(ctx context.Context, uid, nic string, endpoint *spiderpoolv1.SpiderEndpoint) (*models.IpamAddResponse, error) {
 	logger := logutils.FromContext(ctx)
 
-	allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic, endpoint)
+	// Create -> Delete -> Create a Pod with the same namespace and name in
+	// a short time will cause some unexpected phenomena discussed in
+	// https://github.com/spidernet-io/spiderpool/issues/1187.
+	if endpoint != nil && endpoint.Status.Current.UID != uid {
+		return nil, fmt.Errorf("currently, the IP allocation of the Pod %s/%s (UID: %s) is being recycled. You may create two Pods with the same namespace and name in a very short time", endpoint.Namespace, endpoint.Name, endpoint.Status.Current.UID)
+	}
+
+	allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic, endpoint, false)
 	if allocation == nil {
 		logger.Debug("Nothing retrieved to allocate")
 		return nil, nil
@@ -218,7 +225,7 @@ func (i *ipam) allocateInStandardMode(ctx context.Context, addArgs *models.IpamA
 	}
 
 	logger.Debug("Patch IP allocation results to Endpoint")
-	if err = i.endpointManager.PatchIPAllocationResults(ctx, *addArgs.ContainerID, results, endpoint, pod, podController); err != nil {
+	if err = i.endpointManager.PatchIPAllocationResults(ctx, results, endpoint, pod, podController); err != nil {
 		return nil, fmt.Errorf("failed to patch IP allocation results to Endpoint: %v", err)
 	}
 
diff --git a/pkg/ipam/release.go b/pkg/ipam/release.go
index d61cd1955..fbcefda75 100644
--- a/pkg/ipam/release.go
+++ b/pkg/ipam/release.go
@@ -107,7 +107,7 @@ func (i *ipam) releaseForAllNICs(ctx context.Context, uid, nic string, endpoint
 		}
 	}
 
-	allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic, endpoint)
+	allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic, endpoint, false)
 	if allocation == nil {
 		logger.Info("Nothing retrieved for releasing")
 		return nil
diff --git a/pkg/k8s/apis/spiderpool.spidernet.io/v1/spiderendpoint_types.go b/pkg/k8s/apis/spiderpool.spidernet.io/v1/spiderendpoint_types.go
index fe683d017..04e8c1c94 100644
--- a/pkg/k8s/apis/spiderpool.spidernet.io/v1/spiderendpoint_types.go
+++ b/pkg/k8s/apis/spiderpool.spidernet.io/v1/spiderendpoint_types.go
@@ -23,9 +23,6 @@ type WorkloadEndpointStatus struct {
 }
 
 type PodIPAllocation struct {
-	// +kubebuilder:validation:Required
-	ContainerID string `json:"containerID"`
-
 	// +kubebuilder:validation:Required
 	UID string `json:"uid"`
 
diff --git a/pkg/k8s/apis/spiderpool.spidernet.io/v1/types_string.go b/pkg/k8s/apis/spiderpool.spidernet.io/v1/types_string.go
index fdb3e103a..667a2d462 100644
--- a/pkg/k8s/apis/spiderpool.spidernet.io/v1/types_string.go
+++ b/pkg/k8s/apis/spiderpool.spidernet.io/v1/types_string.go
@@ -107,7 +107,6 @@ func (in *PodIPAllocation) String() string {
 	repeatedStringForIPs += "}"
 
 	s := strings.Join([]string{`&PodIPAllocation{`,
-		`ContainerID:` + fmt.Sprintf("%+v", in.ContainerID) + `,`,
 		`UID:` + fmt.Sprintf("%+v", in.UID) + `,`,
 		`Node:` + stringutil.ValueToStringGenerated(in.Node) + `,`,
 		`IPs:` + repeatedStringForIPs + `,`,
diff --git a/pkg/utils/convert/convert.go b/pkg/utils/convert/convert.go
index 7a19a31e7..5a0c75305 100644
--- a/pkg/utils/convert/convert.go
+++ b/pkg/utils/convert/convert.go
@@ -22,7 +22,6 @@ func ConvertIPDetailsToIPConfigsAndAllRoutes(details []spiderpoolv1.IPAllocation
 	var routes []*models.Route
 	for _, d := range details {
 		nic := d.NIC
-
 		if d.IPv4 != nil {
 			version := constant.IPv4
 			var ipv4Gateway string
@@ -107,30 +106,31 @@ func genDefaultRoute(nic, gateway string) *models.Route {
 
 func ConvertResultsToIPDetails(results []*types.AllocationResult) []spiderpoolv1.IPAllocationDetail {
 	nicToDetail := map[string]*spiderpoolv1.IPAllocationDetail{}
-	var cleanGateway *bool
 	for _, r := range results {
 		var gateway *string
+		var cleanGateway *bool
 		if r.IP.Gateway != "" {
 			gateway = new(string)
+			cleanGateway = new(bool)
 			*gateway = r.IP.Gateway
-			if cleanGateway == nil {
-				cleanGateway = new(bool)
-				*cleanGateway = r.CleanGateway
-			}
+			*cleanGateway = r.CleanGateway
 		}
+
+		address := *r.IP.Address
+		pool := r.IP.IPPool
+		vlan := r.IP.Vlan
 		routes := ConvertOAIRoutesToSpecRoutes(r.Routes)
+
 		if d, ok := nicToDetail[*r.IP.Nic]; ok {
 			if *r.IP.Version == constant.IPv4 {
-				d.IPv4 = r.IP.Address
-				d.IPv4Pool = &r.IP.IPPool
+				d.IPv4 = &address
+				d.IPv4Pool = &pool
 				d.IPv4Gateway = gateway
-				d.CleanGateway = cleanGateway
 				d.Routes = append(d.Routes, routes...)
 			} else {
 				d.IPv6 = r.IP.Address
 				d.IPv6Pool = &r.IP.IPPool
 				d.IPv6Gateway = gateway
-				d.CleanGateway = cleanGateway
 				d.Routes = append(d.Routes, routes...)
 			}
 			continue
@@ -139,9 +139,9 @@ func ConvertResultsToIPDetails(results []*types.AllocationResult) []spiderpoolv1
 		if *r.IP.Version == constant.IPv4 {
 			nicToDetail[*r.IP.Nic] = &spiderpoolv1.IPAllocationDetail{
 				NIC:          *r.IP.Nic,
-				IPv4:         r.IP.Address,
-				IPv4Pool:     &r.IP.IPPool,
-				Vlan:         &r.IP.Vlan,
+				IPv4:         &address,
+				IPv4Pool:     &pool,
+				Vlan:         &vlan,
 				IPv4Gateway:  gateway,
 				CleanGateway: cleanGateway,
 				Routes:       routes,
@@ -149,9 +149,9 @@ func ConvertResultsToIPDetails(results []*types.AllocationResult) []spiderpoolv1
 		} else {
 			nicToDetail[*r.IP.Nic] = &spiderpoolv1.IPAllocationDetail{
 				NIC:          *r.IP.Nic,
-				IPv6:         r.IP.Address,
-				IPv6Pool:     &r.IP.IPPool,
-				Vlan:         &r.IP.Vlan,
+				IPv6:         &address,
+				IPv6Pool:     &pool,
+				Vlan:         &vlan,
 				IPv6Gateway:  gateway,
 				CleanGateway: cleanGateway,
 				Routes:       routes,
diff --git a/pkg/workloadendpointmanager/utils.go b/pkg/workloadendpointmanager/utils.go
index 92de553ca..c9eaf125d 100644
--- a/pkg/workloadendpointmanager/utils.go
+++ b/pkg/workloadendpointmanager/utils.go
@@ -7,12 +7,12 @@ import (
 	spiderpoolv1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v1"
 )
 
-func RetrieveIPAllocation(uid, nic string, endpoint *spiderpoolv1.SpiderEndpoint) *spiderpoolv1.PodIPAllocation {
+func RetrieveIPAllocation(uid, nic string, endpoint *spiderpoolv1.SpiderEndpoint, isSTS bool) *spiderpoolv1.PodIPAllocation {
 	if endpoint == nil {
 		return nil
 	}
 
-	if endpoint.Status.Current.UID == uid {
+	if endpoint.Status.Current.UID == uid || isSTS {
 		for _, d := range endpoint.Status.Current.IPs {
 			if d.NIC == nic {
 				return &endpoint.Status.Current
diff --git a/pkg/workloadendpointmanager/workloadendpoint_manager.go b/pkg/workloadendpointmanager/workloadendpoint_manager.go
index e0ebe6a64..a398d5fd6 100644
--- a/pkg/workloadendpointmanager/workloadendpoint_manager.go
+++ b/pkg/workloadendpointmanager/workloadendpoint_manager.go
@@ -27,8 +27,8 @@ type WorkloadEndpointManager interface {
 	ListEndpoints(ctx context.Context, cached bool, opts ...client.ListOption) (*spiderpoolv1.SpiderEndpointList, error)
 	DeleteEndpoint(ctx context.Context, endpoint *spiderpoolv1.SpiderEndpoint) error
 	RemoveFinalizer(ctx context.Context, namespace, podName string) error
-	PatchIPAllocationResults(ctx context.Context, containerID string, results []*types.AllocationResult, endpoint *spiderpoolv1.SpiderEndpoint, pod *corev1.Pod, podController types.PodTopController) error
-	ReallocateCurrentIPAllocation(ctx context.Context, containerID, uid, nodeName string, endpoint *spiderpoolv1.SpiderEndpoint) error
+	PatchIPAllocationResults(ctx context.Context, results []*types.AllocationResult, endpoint *spiderpoolv1.SpiderEndpoint, pod *corev1.Pod, podController types.PodTopController) error
+	ReallocateCurrentIPAllocation(ctx context.Context, uid, nodeName string, endpoint *spiderpoolv1.SpiderEndpoint) error
 }
 
 type workloadEndpointManager struct {
@@ -117,18 +117,11 @@ func (em *workloadEndpointManager) RemoveFinalizer(ctx context.Context, namespac
 	return nil
 }
 
-func (em *workloadEndpointManager) PatchIPAllocationResults(ctx context.Context, containerID string, results []*types.AllocationResult, endpoint *spiderpoolv1.SpiderEndpoint, pod *corev1.Pod, podController types.PodTopController) error {
+func (em *workloadEndpointManager) PatchIPAllocationResults(ctx context.Context, results []*types.AllocationResult, endpoint *spiderpoolv1.SpiderEndpoint, pod *corev1.Pod, podController types.PodTopController) error {
 	if pod == nil {
 		return fmt.Errorf("pod %w", constant.ErrMissingRequiredParam)
 	}
 
-	allocation := spiderpoolv1.PodIPAllocation{
-		ContainerID: containerID,
-		UID:         string(pod.UID),
-		Node:        pod.Spec.NodeName,
-		IPs:         convert.ConvertResultsToIPDetails(results),
-	}
-
 	if endpoint == nil {
 		endpoint = &spiderpoolv1.SpiderEndpoint{
 			ObjectMeta: metav1.ObjectMeta{
@@ -136,7 +129,11 @@ func (em *workloadEndpointManager) PatchIPAllocationResults(ctx context.Context,
 				Namespace: pod.Namespace,
 			},
 			Status: spiderpoolv1.WorkloadEndpointStatus{
-				Current:             allocation,
+				Current: spiderpoolv1.PodIPAllocation{
+					UID:  string(pod.UID),
+					Node: pod.Spec.NodeName,
+					IPs:  convert.ConvertResultsToIPDetails(results),
+				},
 				OwnerControllerType: podController.Kind,
 				OwnerControllerName: podController.Name,
 				CreationTime:        metav1.Time{Time: time.Now()},
@@ -156,26 +153,24 @@ func (em *workloadEndpointManager) PatchIPAllocationResults(ctx context.Context,
 		return em.client.Create(ctx, endpoint)
 	}
 
-	if endpoint.Status.Current.ContainerID == containerID &&
-		endpoint.Status.Current.UID == string(pod.UID) {
+	if endpoint.Status.Current.UID != string(pod.UID) {
 		return nil
 	}
 
-	endpoint.Status.Current = allocation
+	// TODO(iiiceoo): Only append records with different NIC.
+	endpoint.Status.Current.IPs = append(endpoint.Status.Current.IPs, convert.ConvertResultsToIPDetails(results)...)
 	return em.client.Update(ctx, endpoint)
 }
 
-func (em *workloadEndpointManager) ReallocateCurrentIPAllocation(ctx context.Context, containerID, uid, nodeName string, endpoint *spiderpoolv1.SpiderEndpoint) error {
+func (em *workloadEndpointManager) ReallocateCurrentIPAllocation(ctx context.Context, uid, nodeName string, endpoint *spiderpoolv1.SpiderEndpoint) error {
 	if endpoint == nil {
 		return fmt.Errorf("endpoint %w", constant.ErrMissingRequiredParam)
 	}
 
-	if endpoint.Status.Current.ContainerID == containerID &&
-		endpoint.Status.Current.UID == uid {
+	if endpoint.Status.Current.UID == uid {
 		return nil
 	}
 
-	endpoint.Status.Current.ContainerID = containerID
 	endpoint.Status.Current.UID = uid
 	endpoint.Status.Current.Node = nodeName
 


Test patch:
diff --git a/pkg/workloadendpointmanager/utils_test.go b/pkg/workloadendpointmanager/utils_test.go
index b1518a5d8..2760fb402 100644
--- a/pkg/workloadendpointmanager/utils_test.go
+++ b/pkg/workloadendpointmanager/utils_test.go
@@ -64,21 +64,28 @@ var _ = Describe("WorkloadEndpointManager utils", Label("workloadendpoint_manage
 		})
 
 		It("inputs nil Endpoint", func() {
-			allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic2, nil)
+			allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic2, nil, false)
 			Expect(allocation).To(BeNil())
 		})
 
 		It("retrieves non-existent current IP allocation", func() {
 			endpointT.Status.Current = allocationT
 
-			allocation := workloadendpointmanager.RetrieveIPAllocation(string(uuid.NewUUID()), nic2, endpointT)
+			allocation := workloadendpointmanager.RetrieveIPAllocation(string(uuid.NewUUID()), nic2, endpointT, false)
 			Expect(allocation).To(BeNil())
 		})
 
 		It("retrieves the current IP allocation", func() {
 			endpointT.Status.Current = allocationT
 
-			allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic2, endpointT)
+			allocation := workloadendpointmanager.RetrieveIPAllocation(uid, nic2, endpointT, false)
+			Expect(*allocation).To(Equal(allocationT))
+		})
+
+		It("retrieves the IP allocation of StatefulSet", func() {
+			endpointT.Status.Current = allocationT
+
+			allocation := workloadendpointmanager.RetrieveIPAllocation(string(uuid.NewUUID()), nic2, endpointT, true)
 			Expect(*allocation).To(Equal(allocationT))
 		})
 	})
diff --git a/pkg/workloadendpointmanager/workloadendpoint_manager_test.go b/pkg/workloadendpointmanager/workloadendpoint_manager_test.go
index f31f5c95f..275d83482 100644
--- a/pkg/workloadendpointmanager/workloadendpoint_manager_test.go
+++ b/pkg/workloadendpointmanager/workloadendpoint_manager_test.go
@@ -351,7 +351,7 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 			})
 
 			It("inputs nil Pod", func() {
-				err := endpointManager.PatchIPAllocationResults(ctx, "", []*spiderpooltypes.AllocationResult{}, nil, nil, spiderpooltypes.PodTopController{})
+				err := endpointManager.PatchIPAllocationResults(ctx, []*spiderpooltypes.AllocationResult{}, nil, nil, spiderpooltypes.PodTopController{})
 				Expect(err).To(MatchError(constant.ErrMissingRequiredParam))
 			})
 
@@ -359,7 +359,7 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 				patches := gomonkey.ApplyFuncReturn(controllerutil.SetOwnerReference, constant.ErrUnknown)
 				defer patches.Reset()
 
-				err := endpointManager.PatchIPAllocationResults(ctx, "", []*spiderpooltypes.AllocationResult{}, nil, podT, spiderpooltypes.PodTopController{})
+				err := endpointManager.PatchIPAllocationResults(ctx, []*spiderpooltypes.AllocationResult{}, nil, podT, spiderpooltypes.PodTopController{})
 				Expect(err).To(MatchError(constant.ErrUnknown))
 			})
 
@@ -367,14 +367,13 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 				patches := gomonkey.ApplyMethodReturn(fakeClient, "Create", constant.ErrUnknown)
 				defer patches.Reset()
 
-				err := endpointManager.PatchIPAllocationResults(ctx, "", []*spiderpooltypes.AllocationResult{}, nil, podT, spiderpooltypes.PodTopController{})
+				err := endpointManager.PatchIPAllocationResults(ctx, []*spiderpooltypes.AllocationResult{}, nil, podT, spiderpooltypes.PodTopController{})
 				Expect(err).To(MatchError(constant.ErrUnknown))
 			})
 
 			It("creates Endpoint for orphan Pod", func() {
 				err := endpointManager.PatchIPAllocationResults(
 					ctx,
-					"",
 					[]*spiderpooltypes.AllocationResult{},
 					nil,
 					podT,
@@ -400,7 +399,6 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 			It("creates Endpoint for StatefulSet Pod", func() {
 				err := endpointManager.PatchIPAllocationResults(
 					ctx,
-					"",
 					[]*spiderpooltypes.AllocationResult{},
 					nil,
 					podT,
@@ -423,12 +421,11 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 				Expect(controllerutil.ContainsFinalizer(&endpoint, constant.SpiderFinalizer))
 			})
 
-			It("patches IP allocation results with the same container ID and Pod UID", func() {
-				uid := uuid.NewUUID()
-				podT.SetUID(uid)
-				endpointT.Status.Current.UID = string(uid)
+			It("patches IP allocation results with different Pod UID", func() {
+				podT.SetUID(uuid.NewUUID())
+				endpointT.Status.Current.UID = string(uuid.NewUUID())
 
-				err := endpointManager.PatchIPAllocationResults(ctx, "", []*spiderpooltypes.AllocationResult{}, endpointT, podT, spiderpooltypes.PodTopController{})
+				err := endpointManager.PatchIPAllocationResults(ctx, []*spiderpooltypes.AllocationResult{}, endpointT, podT, spiderpooltypes.PodTopController{})
 				Expect(err).NotTo(HaveOccurred())
 			})
 
@@ -436,7 +433,11 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 				patches := gomonkey.ApplyMethodReturn(fakeClient, "Update", constant.ErrUnknown)
 				defer patches.Reset()
 
-				err := endpointManager.PatchIPAllocationResults(ctx, "", []*spiderpooltypes.AllocationResult{}, endpointT, podT, spiderpooltypes.PodTopController{})
+				uid := uuid.NewUUID()
+				podT.SetUID(uid)
+				endpointT.Status.Current.UID = string(uid)
+
+				err := endpointManager.PatchIPAllocationResults(ctx, []*spiderpooltypes.AllocationResult{}, endpointT, podT, spiderpooltypes.PodTopController{})
 				Expect(err).To(MatchError(constant.ErrUnknown))
 			})
 
@@ -444,15 +445,15 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 
 		Describe("ReallocateCurrentIPAllocation", func() {
 			It("inputs nil Endpoint", func() {
-				err := endpointManager.ReallocateCurrentIPAllocation(ctx, "", string(uuid.NewUUID()), "node1", nil)
+				err := endpointManager.ReallocateCurrentIPAllocation(ctx, string(uuid.NewUUID()), "node1", nil)
 				Expect(err).To(MatchError(constant.ErrMissingRequiredParam))
 			})
 
-			It("re-allocates the current IP allocation with the same container ID and Pod UID", func() {
+			It("re-allocates the current IP allocation with the same Pod UID", func() {
 				uid := uuid.NewUUID()
 				endpointT.Status.Current.UID = string(uid)
 
-				err := endpointManager.ReallocateCurrentIPAllocation(ctx, "", string(uid), "node", endpointT)
+				err := endpointManager.ReallocateCurrentIPAllocation(ctx, string(uid), "node", endpointT)
 				Expect(err).NotTo(HaveOccurred())
 			})
 
@@ -462,7 +463,7 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 
 				endpointT.Status.Current.UID = string(uuid.NewUUID())
 
-				err := endpointManager.ReallocateCurrentIPAllocation(ctx, "", string(uuid.NewUUID()), "node", endpointT)
+				err := endpointManager.ReallocateCurrentIPAllocation(ctx, string(uuid.NewUUID()), "node", endpointT)
 				Expect(err).To(MatchError(constant.ErrUnknown))
 			})
 
@@ -476,7 +477,7 @@ var _ = Describe("WorkloadEndpointManager", Label("workloadendpoint_manager_test
 				uid := string(uuid.NewUUID())
 				nodeName := "new-node"
 
-				err = endpointManager.ReallocateCurrentIPAllocation(ctx, "", uid, nodeName, endpointT)
+				err = endpointManager.ReallocateCurrentIPAllocation(ctx, uid, nodeName, endpointT)
 				Expect(err).NotTo(HaveOccurred())
 				Expect(endpointT.Status.Current.UID).To(Equal(uid))
 				Expect(endpointT.Status.Current.Node).To(Equal(nodeName))