This commit is contained in:
@@ -18,7 +18,6 @@ package cloudprovider
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
@@ -43,17 +42,8 @@ type Clusters interface {
|
|||||||
Master(clusterName string) (string, error)
|
Master(clusterName string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(#6812): Use a shorter name that's less likely to be longer than cloud
|
func GetLoadBalancerName(clusterName, serviceNamespace, serviceName string) string {
|
||||||
// providers' name length limits.
|
return clusterName + "-" + serviceNamespace + "-" + serviceName
|
||||||
func GetLoadBalancerName(service *api.Service) string {
|
|
||||||
//GCE requires that the name of a load balancer starts with a lower case letter.
|
|
||||||
ret := "a" + string(service.UID)
|
|
||||||
ret = strings.Replace(ret, "-", "", -1)
|
|
||||||
//AWS requires that the name of a load balancer is shorter than 32 bytes.
|
|
||||||
if len(ret) > 32 {
|
|
||||||
ret = ret[:32]
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
|
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
|
||||||
|
@@ -438,7 +438,7 @@ func needsUpdate(oldService *api.Service, newService *api.Service) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServiceController) loadBalancerName(service *api.Service) string {
|
func (s *ServiceController) loadBalancerName(service *api.Service) string {
|
||||||
return cloudprovider.GetLoadBalancerName(service)
|
return cloudprovider.GetLoadBalancerName(s.clusterName, service.Namespace, service.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTCPPorts(service *api.Service) ([]int, error) {
|
func getTCPPorts(service *api.Service) ([]int, error) {
|
||||||
@@ -571,7 +571,7 @@ func (s *ServiceController) lockedUpdateLoadBalancerHosts(service *api.Service,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
name := cloudprovider.GetLoadBalancerName(service)
|
name := s.loadBalancerName(service)
|
||||||
err := s.balancer.UpdateTCPLoadBalancer(name, s.zone.Region, hosts)
|
err := s.balancer.UpdateTCPLoadBalancer(name, s.zone.Region, hosts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@@ -27,9 +27,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const region = "us-central"
|
const region = "us-central"
|
||||||
|
const clusterName = "test-cluster"
|
||||||
|
const namespace = "namespace"
|
||||||
|
|
||||||
func newService(name string, uid types.UID, external bool) *api.Service {
|
func newService(name string, uid types.UID, external bool) *api.Service {
|
||||||
return &api.Service{ObjectMeta: api.ObjectMeta{Name: name, Namespace: "namespace", UID: uid}, Spec: api.ServiceSpec{CreateExternalLoadBalancer: external}}
|
return &api.Service{ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespace, UID: uid}, Spec: api.ServiceSpec{CreateExternalLoadBalancer: external}}
|
||||||
|
}
|
||||||
|
func lbName(serviceName string) string {
|
||||||
|
return clusterName + "-" + namespace + "-" + serviceName
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateExternalLoadBalancer(t *testing.T) {
|
func TestCreateExternalLoadBalancer(t *testing.T) {
|
||||||
@@ -91,7 +96,7 @@ func TestCreateExternalLoadBalancer(t *testing.T) {
|
|||||||
cloud := &fake_cloud.FakeCloud{}
|
cloud := &fake_cloud.FakeCloud{}
|
||||||
cloud.Region = region
|
cloud.Region = region
|
||||||
client := &testclient.Fake{}
|
client := &testclient.Fake{}
|
||||||
controller := New(cloud, client, "test-cluster")
|
controller := New(cloud, client, clusterName)
|
||||||
controller.init()
|
controller.init()
|
||||||
cloud.Calls = nil // ignore any cloud calls made in init()
|
cloud.Calls = nil // ignore any cloud calls made in init()
|
||||||
client.Actions = nil // ignore any client calls made in init()
|
client.Actions = nil // ignore any client calls made in init()
|
||||||
@@ -155,7 +160,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
|
|||||||
newService("s0", "333", true),
|
newService("s0", "333", true),
|
||||||
},
|
},
|
||||||
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
||||||
{Name: "a333", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s0"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -166,9 +171,9 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
|
|||||||
newService("s2", "666", true),
|
newService("s2", "666", true),
|
||||||
},
|
},
|
||||||
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
||||||
{Name: "a444", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s0"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
{Name: "a555", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s1"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
{Name: "a666", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s2"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -180,8 +185,8 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
|
|||||||
newService("s4", "123", false),
|
newService("s4", "123", false),
|
||||||
},
|
},
|
||||||
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
expectedUpdateCalls: []fake_cloud.FakeUpdateBalancerCall{
|
||||||
{Name: "a888", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s1"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
{Name: "a999", Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
{Name: lbName("s3"), Region: region, Hosts: []string{"node0", "node1", "node73"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -190,7 +195,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
|
|||||||
|
|
||||||
cloud.Region = region
|
cloud.Region = region
|
||||||
client := &testclient.Fake{}
|
client := &testclient.Fake{}
|
||||||
controller := New(cloud, client, "test-cluster2")
|
controller := New(cloud, client, clusterName)
|
||||||
controller.init()
|
controller.init()
|
||||||
cloud.Calls = nil // ignore any cloud calls made in init()
|
cloud.Calls = nil // ignore any cloud calls made in init()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user