Skip to content

Commit 2d3e8d8

Browse files
committed
fix ip clean (#5193)
Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
1 parent c53e562 commit 2d3e8d8

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

pkg/controller/init.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ func (c *Controller) InitIPAM() error {
371371
}
372372

373373
for _, ip := range ips {
374+
if !ip.DeletionTimestamp.IsZero() {
375+
klog.Infof("enqueue update for removing finalizer to delete ip %s", ip.Name)
376+
c.updateIPQueue.Add(ip.Name)
377+
continue
378+
}
374379
// recover sts and kubevirt vm ip, other ip recover in later pod loop
375380
if ip.Spec.PodType != util.StatefulSet && ip.Spec.PodType != util.VM {
376381
continue
@@ -625,8 +630,8 @@ func (c *Controller) syncIPCR() error {
625630

626631
ipMap := strset.New(c.getVMLsps()...)
627632
for _, ip := range ips {
628-
if !ip.DeletionTimestamp.IsZero() && len(ip.GetFinalizers()) != 0 {
629-
klog.Infof("enqueue update for deleting ip %s", ip.Name)
633+
if !ip.DeletionTimestamp.IsZero() {
634+
klog.Infof("enqueue update for removing finalizer to delete ip %s", ip.Name)
630635
c.updateIPQueue.Add(ip.Name)
631636
continue
632637
}

pkg/controller/ip.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ func (c *Controller) handleAddReservedIP(key string) error {
228228
return err
229229
}
230230
klog.V(3).Infof("handle add reserved ip %s", ip.Name)
231+
if !ip.DeletionTimestamp.IsZero() {
232+
klog.Infof("handle add process stop for deleting ip %s", ip.Name)
233+
return nil
234+
}
231235
if ip.Spec.Subnet == "" {
232236
err := errors.New("subnet parameter cannot be empty")
233237
klog.Error(err)
@@ -510,7 +514,12 @@ func (c *Controller) createOrUpdateIPCR(ipCRName, podName, ip, mac, subnetName,
510514
// the returned pointer is not nil if the CR does not exist
511515
ipCR = nil
512516
}
513-
517+
if ipCR != nil && !ipCR.DeletionTimestamp.IsZero() {
518+
// this ip is being deleted, no need to update
519+
klog.Infof("enqueue update for removing finalizer to delete ip %s", ipCR.Name)
520+
c.updateIPQueue.Add(ipCR.Name)
521+
return nil
522+
}
514523
v4IP, v6IP := util.SplitStringIP(ip)
515524
if ipCR == nil {
516525
ipCR, err = c.config.KubeOvnClient.KubeovnV1().IPs().Create(context.Background(), &kubeovnv1.IP{

0 commit comments

Comments
 (0)