Skip to content

Commit 1f0cb69

Browse files
authored
Merge pull request spidernet-io#4729 from spidernet-io/pr/welan/ip
fix: retrieve the endpoint for deleted stateless pod
2 parents c1eeeff + ea7a8fd commit 1f0cb69

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/gcmanager/scanAll_IPPool.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) {
126126
flagStaticIPPod := false
127127
endpoint, endpointErr := s.wepMgr.GetEndpointByName(ctx, podNS, podName, constant.UseCache)
128128
podYaml, podErr := s.podMgr.GetPodByName(ctx, podNS, podName, constant.UseCache)
129+
130+
// handle the pod not existed with the same name
129131
if podErr != nil {
130132
// case: The pod in IPPool's ip-allocationDetail is not exist in k8s
131133
if apierrors.IsNotFound(podErr) {
@@ -168,6 +170,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) {
168170
continue
169171
}
170172

173+
// check the pod status
171174
switch {
172175
case podYaml.Status.Phase == corev1.PodSucceeded || podYaml.Status.Phase == corev1.PodFailed:
173176
wrappedLog := scanAllLogger.With(zap.String("gc-reason", fmt.Sprintf("The current state of the Pod %s/%s is: %v", podNS, podName, podYaml.Status.Phase)))
@@ -263,7 +266,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) {
263266
}
264267
}
265268

266-
// handle the IP in ippool
269+
// handle same name pod with different uid in the ippool
267270
if string(podYaml.UID) != poolIPAllocation.PodUID {
268271
wrappedLog := scanAllLogger.With(zap.String("gc-reason", fmt.Sprintf("Pod: %s/%s UID %s is different from IPPool: %s UID %s", podNS, podName, podYaml.UID, pool.Name, poolIPAllocation.PodUID)))
269272
if flagStaticIPPod {
@@ -311,6 +314,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) {
311314
flagGCEndpoint = false
312315
}
313316
} else {
317+
// handle same name pod with different uid in the endpoint
314318
if string(podYaml.UID) != endpoint.Status.Current.UID {
315319
wrappedLog := scanAllLogger.With(zap.String("gc-reason", fmt.Sprintf("Pod:%s/%s UID %s is different from endpoint:%s/%s UID %s", podNS, podName, podYaml.UID, endpoint.Namespace, endpoint.Name, poolIPAllocation.PodUID)))
316320
if flagStaticIPPod {
@@ -337,6 +341,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) {
337341
} else {
338342
wrappedLog.Sugar().Infof("pod %s/%s is not a static Pod with a status of %v, the endpoint %v/%v should be reclaimed", podNS, podName, podYaml.Status.Phase, endpoint.Namespace, endpoint.Name)
339343
flagGCIPPoolIP = true
344+
flagGCEndpoint = true
340345
}
341346
} else {
342347
if flagPodStatusShouldGCIP {

0 commit comments

Comments
 (0)