Skip to content

Commit

Permalink
fix: create/delete order might lead ip conflict
Browse files Browse the repository at this point in the history
(cherry picked from commit 7927237)
  • Loading branch information
oilbeater committed Jun 19, 2020
1 parent 0656f63 commit 88b847c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,24 @@ func (c *Controller) handleAddPod(key string) error {
}

func (c *Controller) handleDeletePod(key string) error {
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key))
return nil
}
pod, err := c.podsLister.Pods(namespace).Get(name)
if pod != nil && isPodAlive(pod) {
// Pod with same name exists, just return here
return nil
}

ips, _ := c.ipam.GetPodAddress(key)
for _, ip := range ips {
if err := c.ovnClient.DeleteStaticRoute(ip, c.config.ClusterRouter); err != nil {
return err
}
}

namespace, name, err := cache.SplitMetaNamespaceKey(key)
klog.Infof("delete pod %s/%s", namespace, name)
if err != nil {
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key))
return err
}

if err := c.ovnClient.DeletePort(ovs.PodNameToPortName(name, namespace)); err != nil {
klog.Errorf("failed to delete lsp %s, %v", ovs.PodNameToPortName(name, namespace), err)
return err
Expand Down

0 comments on commit 88b847c

Please sign in to comment.