Change proxy config to reuse util/config

Splits endpoint and service configuration into their own objects.  Also makes
the endpoint and service configuration tests correct - there was a race condition
previously that meant tests were passing but not checking correct code.
This commit is contained in:
Clayton Coleman
2014-07-08 12:55:11 -04:00
parent 38ec4ff8c0
commit 021cf64808
5 changed files with 315 additions and 338 deletions

View File

@@ -41,27 +41,27 @@ func main() {
glog.Infof("Using configuration file %s and etcd_servers %s", *configFile, *etcdServers)
proxyConfig := config.NewServiceConfig()
serviceConfig := config.NewServiceConfig()
endpointsConfig := config.NewEndpointsConfig()
// Create a configuration source that handles configuration from etcd.
etcdClient := etcd.NewClient([]string{*etcdServers})
config.NewConfigSourceEtcd(etcdClient,
proxyConfig.GetServiceConfigurationChannel("etcd"),
proxyConfig.GetEndpointsConfigurationChannel("etcd"))
serviceConfig.Channel("etcd"),
endpointsConfig.Channel("etcd"))
// And create a configuration source that reads from a local file
config.NewConfigSourceFile(*configFile,
proxyConfig.GetServiceConfigurationChannel("file"),
proxyConfig.GetEndpointsConfigurationChannel("file"))
serviceConfig.Channel("file"),
endpointsConfig.Channel("file"))
loadBalancer := proxy.NewLoadBalancerRR()
proxier := proxy.NewProxier(loadBalancer)
// Wire proxier to handle changes to services
proxyConfig.RegisterServiceHandler(proxier)
serviceConfig.RegisterHandler(proxier)
// And wire loadBalancer to handle changes to endpoints to services
proxyConfig.RegisterEndpointsHandler(loadBalancer)
endpointsConfig.RegisterHandler(loadBalancer)
// Just loop forever for now...
select {}
}