Skip to content

Commit

Permalink
fix adding static route after LSP deletion (#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jun 6, 2022
1 parent f7ee860 commit f5c3ed3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,22 +714,28 @@ func (c *Controller) handleUpdatePod(key string) error {
c.podKeyMutex.Lock(key)
defer c.podKeyMutex.Unlock(key)

oripod, err := c.podsLister.Pods(namespace).Get(name)
cachedPod, err := c.podsLister.Pods(namespace).Get(name)
if err != nil {
if k8serrors.IsNotFound(err) {
return nil
}
return err
}
podName := c.getNameByPod(oripod)
pod := oripod.DeepCopy()
if cachedPod.DeletionTimestamp != nil || !isPodAlive(cachedPod) {
return nil
}

// in case update handler overlap the annotation when cache is not in sync
if pod.Annotations[util.AllocatedAnnotation] == "" {
if len(cachedPod.Annotations) == 0 || cachedPod.Annotations[util.AllocatedAnnotation] == "" {
return fmt.Errorf("no address has been allocated to %s/%s", namespace, name)
}
if cachedPod.Annotations[util.RoutedAnnotation] == "true" {
// no need to handle the Pod
return nil
}

klog.Infof("update pod %s/%s", namespace, name)
pod := cachedPod.DeepCopy()

var podIP string
var subnet *kubeovnv1.Subnet
Expand Down Expand Up @@ -803,6 +809,7 @@ func (c *Controller) handleUpdatePod(key string) error {
}

if c.config.EnableEipSnat {
podName := c.getNameByPod(pod)
for _, ipStr := range strings.Split(podIP, ",") {
if err := c.ovnClient.UpdateNatRule("dnat_and_snat", ipStr, pod.Annotations[util.EipAnnotation], c.config.ClusterRouter, pod.Annotations[util.MacAddressAnnotation], fmt.Sprintf("%s.%s", podName, pod.Namespace)); err != nil {
klog.Errorf("failed to add nat rules, %v", err)
Expand Down

0 comments on commit f5c3ed3

Please sign in to comment.