Commit 0c03f6e7 authored by Tim Hockin's avatar Tim Hockin

Enable public IPs even in not createExternal...

This allows the proxier to portal Public IPs even if the createExternalLoadBalancer flag is not set. This also fixes what appears to be a bug in the createExternalLoadBalancer path wherein multiple PublicIPs would get truncated.
parent b614f229
......@@ -40,8 +40,7 @@ type serviceInfo struct {
timeout time.Duration
mu sync.Mutex // protects active
active bool
// TODO: make this an net.IP address
publicIP []string
publicIP []string // TODO: make this a []net.IP
}
func (si *serviceInfo) isActive() bool {
......@@ -445,7 +444,7 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
if exists && info.isActive() && info.portalPort == service.Spec.Port && info.portalIP.Equal(serviceIP) {
continue
}
if exists && (info.portalPort != service.Spec.Port || !info.portalIP.Equal(serviceIP) || service.Spec.CreateExternalLoadBalancer != (len(info.publicIP) > 0)) {
if exists && (info.portalPort != service.Spec.Port || !info.portalIP.Equal(serviceIP) || !ipsEqual(service.Spec.PublicIPs, info.publicIP)) {
glog.V(4).Infof("Something changed for service %q: stopping it", service.Name)
err := proxier.closePortal(service.Name, info)
if err != nil {
......@@ -464,9 +463,7 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
}
info.portalIP = serviceIP
info.portalPort = service.Spec.Port
if service.Spec.CreateExternalLoadBalancer {
info.publicIP = service.Spec.PublicIPs
}
info.publicIP = service.Spec.PublicIPs
err = proxier.openPortal(service.Name, info)
if err != nil {
glog.Errorf("Failed to open portal for %q: %v", service.Name, err)
......@@ -489,6 +486,18 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
}
}
func ipsEqual(lhs, rhs []string) bool {
if len(lhs) != len(rhs) {
return false
}
for i := range lhs {
if lhs[i] != rhs[i] {
return false
}
}
return true
}
func (proxier *Proxier) openPortal(service string, info *serviceInfo) error {
args := iptablesPortalArgs(info.portalIP, info.portalPort, info.protocol, proxier.listenAddress, info.proxyPort, service)
existed, err := proxier.iptables.EnsureRule(iptables.TableNAT, iptablesProxyChain, args...)
......
......@@ -130,21 +130,21 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if err != nil {
return nil, err
}
var ip net.IP
if len(service.Spec.PublicIPs) > 0 {
for _, publicIP := range service.Spec.PublicIPs {
ip, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, net.ParseIP(publicIP), service.Spec.Port, hostsFromMinionList(hosts))
_, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, net.ParseIP(publicIP), service.Spec.Port, hostsFromMinionList(hosts))
if err != nil {
break
// TODO: have to roll-back any successful calls.
return nil, err
}
}
} else {
ip, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, nil, service.Spec.Port, hostsFromMinionList(hosts))
}
if err != nil {
return nil, err
ip, err := balancer.CreateTCPLoadBalancer(service.Name, zone.Region, nil, service.Spec.Port, hostsFromMinionList(hosts))
if err != nil {
return nil, err
}
service.Spec.PublicIPs = []string{ip.String()}
}
service.Spec.PublicIPs = []string{ip.String()}
}
err := rs.registry.CreateService(ctx, service)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment