Reduce nesting on ServiceRegistryStorage.Create

This commit is contained in:
Kouhei Ueno 2014-08-05 05:38:26 +09:00
parent c8e1c6a02f
commit c6ebc4859e

View File

@ -156,16 +156,17 @@ func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, e
// TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers
// correctly no matter what http operations happen.
if srv.CreateExternalLoadBalancer {
var balancer cloudprovider.TCPLoadBalancer
var zones cloudprovider.Zones
var ok bool
if sr.cloud != nil {
balancer, ok = sr.cloud.TCPLoadBalancer()
if ok {
zones, ok = sr.cloud.Zones()
if sr.cloud == nil {
return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
balancer, ok := sr.cloud.TCPLoadBalancer()
if !ok {
return nil, fmt.Errorf("The cloud provider does not support external TCP load balancers.")
}
zones, ok := sr.cloud.Zones()
if !ok {
return nil, fmt.Errorf("The cloud provider does not support zone enumeration.")
}
if ok && balancer != nil && zones != nil {
hosts, err := sr.machines.List()
if err != nil {
return nil, err
@ -178,9 +179,6 @@ func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, e
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
}
// TODO actually wait for the object to be fully created here.
err := sr.registry.CreateService(srv)