Skip to content

Commit

Permalink
bgp: consolidate service check and use service const (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
lx1036 authored and zhangzujian committed Jul 8, 2022
1 parent 5cffa97 commit 761ddcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/speaker/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
c.informerFactory.Start(stopCh)
c.kubeovnInformerFactory.Start(stopCh)

if ok := cache.WaitForCacheSync(stopCh, c.podsSynced, c.subnetSynced, c.servicesSynced); !ok {
if !cache.WaitForCacheSync(stopCh, c.podsSynced, c.subnetSynced, c.servicesSynced) {
klog.Fatalf("failed to wait for caches to sync")
return
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/speaker/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ func isPodAlive(p *v1.Pod) bool {
return true
}

func isClusterIP(svc *v1.Service) bool {
return svc.Spec.Type == "ClusterIP"
func isClusterIPService(svc *v1.Service) bool {
return svc.Spec.Type == v1.ServiceTypeClusterIP &&
svc.Spec.ClusterIP != v1.ClusterIPNone &&
len(svc.Spec.ClusterIP) != 0
}

// TODO: ipv4 only, need ipv6/dualstack support later
Expand All @@ -60,12 +62,9 @@ func (c *Controller) syncSubnetRoutes() {
return
}
for _, svc := range services {

if isClusterIP(svc) && svc.Annotations[util.BgpAnnotation] == "true" && svc.Spec.ClusterIP != "None" &&
svc.Spec.ClusterIP != "" {
if svc.Annotations != nil && svc.Annotations[util.BgpAnnotation] == "true" && isClusterIPService(svc) {
bgpExpected = append(bgpExpected, fmt.Sprintf("%s/32", svc.Spec.ClusterIP))
}

}
}

Expand Down

0 comments on commit 761ddcb

Please sign in to comment.