LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File keepalived-watch.diff of Package kubernetes-keepalived (Project home:barclaac:hackweek)

diff --git a/keepalived-vip/controller.go b/keepalived-vip/controller.go
index 394aea93..73ab3688 100644
--- a/keepalived-vip/controller.go
+++ controller.go
@@ -24,6 +24,7 @@ import (
 	"os"
 	"reflect"
 	"sort"
+	"strings"
 	"sync"
 	"time"
 
@@ -101,14 +102,20 @@ func (c vipByNameIPPort) Less(i, j int) bool {
 	return iPort < jPort
 }
 
+type storeToConfigMapLister struct {
+	cache.Indexer
+}
+
 // ipvsControllerController watches the kubernetes api and adds/removes
 // services from LVS throgh ipvsadmin.
 type ipvsControllerController struct {
 	client            *unversioned.Client
 	epController      *cache.Controller
 	svcController     *cache.Controller
+	cmController      *cache.Controller
 	svcLister         cache.StoreToServiceLister
 	epLister          cache.StoreToEndpointsLister
+	cmLister          storeToConfigMapLister
 	reloadRateLimiter flowcontrol.RateLimiter
 	keepalived        *keepalived
 	configMapName     string
@@ -383,6 +390,20 @@ func newIPVSController(kubeClient *unversioned.Client, namespace string, useUnic
 			ipvsc.client, "endpoints", namespace, fields.Everything()),
 		&api.Endpoints{}, resyncPeriod, eventHandlers)
 
+	splitConfigMapName := strings.Split(configMapName, "/")
+	if len(splitConfigMapName) == 2 {
+		ipvsc.cmLister.Indexer, ipvsc.cmController = cache.NewIndexerInformer(
+			cache.NewListWatchFromClient(
+				ipvsc.client, "configmaps", namespace,
+				fields.OneTermEqualSelector(api.ObjectNameField, splitConfigMapName[1])),
+			&api.ConfigMap{},
+			resyncPeriod,
+			eventHandlers,
+			cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
+	} else {
+		glog.Warningf("configmap name %s doesn't match <namespace>/<configmap>", configMapName)
+	}
+
 	return &ipvsc
 }
 
diff --git a/keepalived-vip/main.go b/keepalived-vip/main.go
index 226a786e..ef37b7f7 100644
--- a/keepalived-vip/main.go
+++ main.go
@@ -125,6 +125,10 @@ func main() {
 	ipvsc := newIPVSController(kubeClient, namespace, *useUnicast, *configMapName, *vrid)
 	go ipvsc.epController.Run(wait.NeverStop)
 	go ipvsc.svcController.Run(wait.NeverStop)
+	if ipvsc.cmController != nil {
+		// Possibility the controller may not exist if configmap name is malformed
+		go ipvsc.cmController.Run(wait.NeverStop)
+	}
 
 	go ipvsc.syncQueue.run(time.Second, ipvsc.stopCh)