Skip to content

Commit

Permalink
skip ok pod (#3090)
Browse files Browse the repository at this point in the history
* skip ok pod
  • Loading branch information
bobz965 committed Jul 31, 2023
1 parent 18580ed commit 5704dae
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,15 @@ func (c *Controller) enqueueAddPod(obj interface{}) {
return
}

klog.V(3).Infof("enqueue add pod %s", key)
c.addOrUpdatePodQueue.Add(key)
exist, err := c.podNeedSync(p)
if err != nil {
klog.Errorf("invalid pod net: %v", err)
return
}
if exist {
klog.Infof("enqueue add pod %s", key)
c.addOrUpdatePodQueue.Add(key)
}
}

func (c *Controller) enqueueDeletePod(obj interface{}) {
Expand All @@ -239,7 +246,7 @@ func (c *Controller) enqueueDeletePod(obj interface{}) {
return
}

klog.V(3).Infof("enqueue delete pod %s", key)
klog.Infof("enqueue delete pod %s", key)
c.deletingPodObjMap.Store(key, p)
c.deletePodQueue.Add(key)
}
Expand Down Expand Up @@ -337,7 +344,7 @@ func (c *Controller) enqueueUpdatePod(oldObj, newObj interface{}) {
}()
return
}

klog.Infof("enqueue update pod %s", key)
c.addOrUpdatePodQueue.Add(key)

// security policy changed
Expand Down Expand Up @@ -1210,6 +1217,28 @@ func needAllocateSubnets(pod *v1.Pod, nets []*kubeovnNet) []*kubeovnNet {
return result
}

func (c *Controller) podNeedSync(pod *v1.Pod) (bool, error) {
// 1. check annotations
if pod.Annotations == nil {
return true, nil
}
// 2. check annotation ovn subnet
if pod.Annotations[util.RoutedAnnotation] != "true" {
return true, nil
}
// 3. check multus subnet
attachmentNets, err := c.getPodAttachmentNet(pod)
if err != nil {
return false, err
}
for _, n := range attachmentNets {
if pod.Annotations[fmt.Sprintf(util.RoutedAnnotationTemplate, n.ProviderName)] != "true" {
return true, nil
}
}
return false, nil
}

func needRouteSubnets(pod *v1.Pod, nets []*kubeovnNet) []*kubeovnNet {
if !isPodAlive(pod) {
return nil
Expand Down

0 comments on commit 5704dae

Please sign in to comment.