Skip to content

Commit 4eca430

Browse files
andrewsykimmurali-reddy
authored andcommitted
route controller unit tests (#264)
1 parent 542680c commit 4eca430

File tree

5 files changed

+631
-33
lines changed

5 files changed

+631
-33
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kube-router:
2222
@echo Finished kube-router binary build.
2323

2424
test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc)
25-
go test github.com/cloudnativelabs/kube-router/utils/
25+
go test github.com/cloudnativelabs/kube-router/app/... github.com/cloudnativelabs/kube-router/utils/
2626

2727
vagrant-up: export docker=$(DOCKER)
2828
vagrant-up: export DEV_IMG=$(REGISTRY_DEV):$(IMG_TAG)

app/controllers/network_routes_controller.go

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type NetworkRoutingController struct {
4040
nodeSubnet net.IPNet
4141
nodeInterface string
4242
mu sync.Mutex
43-
clientset *kubernetes.Clientset
43+
clientset kubernetes.Interface
4444
bgpServer *gobgp.BgpServer
4545
syncPeriod time.Duration
4646
clusterCIDR string
@@ -227,35 +227,12 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
227227

228228
// advertise cluster IP for the service to be reachable via host
229229
if nrc.advertiseClusterIp {
230-
glog.Infof("Advertising cluster ips of services to the external BGP peers")
231-
for _, svc := range watchers.ServiceWatcher.List() {
232-
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" || svc.Spec.Type == "LoadBalancer" {
233-
234-
// skip headless services
235-
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
236-
continue
237-
}
238-
239-
glog.Infof("found a service of cluster ip type")
240-
nrc.AdvertiseClusterIp(svc.Spec.ClusterIP)
241-
}
242-
}
230+
nrc.advertiseClusterIPs()
243231
}
244232

245233
// advertise cluster IP for the service to be reachable via host
246234
if nrc.advertiseExternalIp {
247-
glog.Infof("Advertising external ips of the services to the external BGP peers")
248-
for _, svc := range watchers.ServiceWatcher.List() {
249-
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" {
250-
// skip headless services
251-
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
252-
continue
253-
}
254-
for _, externalIP := range svc.Spec.ExternalIPs {
255-
nrc.AdvertiseClusterIp(externalIP)
256-
}
257-
}
258-
}
235+
nrc.advertiseExternalIPs()
259236
}
260237

261238
glog.Infof("Performing periodic sync of the routes")
@@ -371,6 +348,43 @@ func (nrc *NetworkRoutingController) watchBgpUpdates() {
371348
}
372349
}
373350

351+
func (nrc *NetworkRoutingController) advertiseClusterIPs() {
352+
glog.Infof("Advertising cluster ips of services to the external BGP peers")
353+
for _, svc := range watchers.ServiceWatcher.List() {
354+
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" || svc.Spec.Type == "LoadBalancer" {
355+
356+
// skip headless services
357+
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
358+
continue
359+
}
360+
361+
glog.Infof("found a service of cluster ip type")
362+
err := nrc.AdvertiseClusterIp(svc.Spec.ClusterIP)
363+
if err != nil {
364+
glog.Errorf("error advertising cluster IP: %q error: %v", svc.Spec.ClusterIP, err)
365+
}
366+
}
367+
}
368+
}
369+
370+
func (nrc *NetworkRoutingController) advertiseExternalIPs() {
371+
glog.Infof("Advertising external ips of the services to the external BGP peers")
372+
for _, svc := range watchers.ServiceWatcher.List() {
373+
if svc.Spec.Type == "ClusterIP" || svc.Spec.Type == "NodePort" {
374+
// skip headless services
375+
if svc.Spec.ClusterIP == "None" || svc.Spec.ClusterIP == "" {
376+
continue
377+
}
378+
for _, externalIP := range svc.Spec.ExternalIPs {
379+
err := nrc.AdvertiseClusterIp(externalIP)
380+
if err != nil {
381+
glog.Errorf("error advertising external IP: %q, error: %v", externalIP, err)
382+
}
383+
}
384+
}
385+
}
386+
}
387+
374388
func (nrc *NetworkRoutingController) advertiseRoute() error {
375389
cidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
376390
if err != nil {

0 commit comments

Comments
 (0)