Skip to content

Commit

Permalink
Merge pull request #491 from alauda/fix/delete-hang
Browse files Browse the repository at this point in the history
fix: delete pod when marked with deletionTimestamp
  • Loading branch information
oilbeater authored Sep 29, 2020
2 parents 4ad7554 + a197665 commit 6f93d61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ func (c *Controller) enqueueUpdatePod(oldObj, newObj interface{}) {
return
}

if newPod.DeletionTimestamp != nil {
go func() {
// In case node get lost and pod can not be deleted,
// the ipaddress will not be recycled
time.Sleep(time.Duration(*newPod.Spec.TerminationGracePeriodSeconds) * time.Second)
c.deletePodQueue.Add(key)
}()
return
}

// pod assigned an ip
if newPod.Annotations[util.AllocatedAnnotation] == "true" &&
newPod.Annotations[util.RoutedAnnotation] != "true" &&
Expand Down Expand Up @@ -410,7 +420,7 @@ func (c *Controller) handleDeletePod(key string) error {
return nil
}
pod, err := c.podsLister.Pods(namespace).Get(name)
if pod != nil && isPodAlive(pod) {
if pod != nil && pod.DeletionTimestamp == nil && isPodAlive(pod) {
// Pod with same name exists, just return here
return nil
}
Expand Down

0 comments on commit 6f93d61

Please sign in to comment.