Skip to content

Commit

Permalink
fix statefulset Pod deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Feb 24, 2022
1 parent b74eacc commit fadc131
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,8 @@ func (c *Controller) enqueueDeletePod(obj interface{}) {
return
}

isStateful, statefulSetName := isStatefulSetPod(p)
if isStateful {
if isStatefulSetPodToDel(c.config.KubeClient, p, statefulSetName) {
klog.V(3).Infof("enqueue delete pod %s", key)
c.deletePodQueue.Add(obj)
}

if delete, err := appendCheckStatefulSetPodToDel(c, p); delete && err == nil {
klog.V(3).Infof("enqueue delete pod %s", key)
c.deletePodQueue.Add(obj)
}
} else {
klog.V(3).Infof("enqueue delete pod %s", key)
c.deletePodQueue.Add(obj)
}
klog.V(3).Infof("enqueue delete pod %s", key)
c.deletePodQueue.Add(obj)
}

func (c *Controller) enqueueUpdatePod(oldObj, newObj interface{}) {
Expand Down Expand Up @@ -570,8 +557,17 @@ func (c *Controller) handleDeletePod(pod *v1.Pod) error {

p, _ := c.podsLister.Pods(pod.Namespace).Get(pod.Name)
if p != nil && p.UID != pod.UID {
// Pod with same name exists, just return here
return nil
// The existing OVN static route with a different nexthop will block creation of the new Pod,
// so we need to check the node names
if pod.Spec.NodeName == "" || pod.Spec.NodeName == p.Spec.NodeName {
// the old Pod has not been scheduled,
// or the new Pod and the old one are scheduled to the same node
return nil
}
if pod.DeletionTimestamp == nil {
// triggered by add/update events, ignore
return nil
}
}

ports, err := c.ovnClient.ListPodLogicalSwitchPorts(pod.Name, pod.Namespace)
Expand Down Expand Up @@ -605,8 +601,15 @@ func (c *Controller) handleDeletePod(pod *v1.Pod) error {

var keepIpCR bool
if ok, sts := isStatefulSetPod(pod); ok {
toDel := isStatefulSetPodToDel(c.config.KubeClient, pod, sts)
delete, err := appendCheckStatefulSetPodToDel(c, pod)
keepIpCR = !isStatefulSetPodToDel(c.config.KubeClient, pod, sts) && !delete && err == nil
if pod.DeletionTimestamp != nil {
// triggered by delete event
if !(toDel || (delete && err == nil)) {
return nil
}
}
keepIpCR = !toDel && !delete && err == nil
}

// Add additional default ports to compatible with previous versions
Expand Down

0 comments on commit fadc131

Please sign in to comment.