Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/app/backend/replicationcontrollerdetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ func getExternalEndpoints(replicationController api.ReplicationController, pods

if service.Spec.Type == api.ServiceTypeNodePort {
externalEndpoints = getNodePortEndpoints(replicationControllerPods, service, getNodeFn)
}

if service.Spec.Type == api.ServiceTypeLoadBalancer {
} else if service.Spec.Type == api.ServiceTypeLoadBalancer {
for _, ingress := range service.Status.LoadBalancer.Ingress {
externalEndpoints = append(externalEndpoints, getExternalEndpoint(ingress,
service.Spec.Ports))
Expand All @@ -343,6 +341,28 @@ func getExternalEndpoints(replicationController api.ReplicationController, pods
}
}

if len(externalEndpoints) == 0 && (service.Spec.Type == api.ServiceTypeNodePort ||
service.Spec.Type == api.ServiceTypeLoadBalancer) {
externalEndpoints = getLocalhostEndpoints(service)
}

return externalEndpoints
}

// Returns localhost endpoints for specified node port or load balancer service.
func getLocalhostEndpoints(service api.Service) []Endpoint {
var externalEndpoints []Endpoint
for _, port := range service.Spec.Ports {
externalEndpoints = append(externalEndpoints, Endpoint{
Host: "localhost",
Ports: []ServicePort{
{
Protocol: port.Protocol,
Port: port.NodePort,
},
},
})
}
return externalEndpoints
}

Expand Down
51 changes: 51 additions & 0 deletions src/test/backend/replicationcontrollerdetail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,57 @@ func TestGetNodePortEndpoints(t *testing.T) {
}
}

func TestGetLocalhostEndpoints(t *testing.T) {
cases := []struct {
service api.Service
expected []Endpoint
}{
{
api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Protocol: "TCP",
NodePort: 30100,
},
{
Protocol: "TCP",
NodePort: 30101,
},
},
},
},
[]Endpoint{
{
Host: "localhost",
Ports: []ServicePort{
{
Port: 30100,
Protocol: "TCP",
},
},
},
{
Host: "localhost",
Ports: []ServicePort{
{
Port: 30101,
Protocol: "TCP",
},
},
},
},
},
}
for _, c := range cases {
actual := getLocalhostEndpoints(c.service)
if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("getLocalhostEndpoints(%+v) == %+v, expected %+v", c.service, actual,
c.expected)
}
}
}

func TestGetInternalEndpoint(t *testing.T) {
cases := []struct {
serviceName, namespace string
Expand Down