Skip to content

Commit

Permalink
Revert "Made the router skip health checks when there is one endpoint"
Browse files Browse the repository at this point in the history
This reverts commit 4833eb5.

This logic is not correct.  If a router is backed by two services, it
will misbehave.
  • Loading branch information
knobunc committed Oct 26, 2017
1 parent e92d5c5 commit 1d0ad23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 152 deletions.
9 changes: 1 addition & 8 deletions pkg/router/template/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,9 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
wasIdled = true
}

// Take a reasonable guess at the number of endpoints to avoid reallocating the out array when we append
out := make([]Endpoint, 0, len(endpoints.Subsets)*4)

// Now build the actual endpoints we pass to the template
// TODO: review me for sanity
for _, s := range subsets {
for _, p := range s.Ports {
if excludeUDP && p.Protocol == kapi.ProtocolUDP {
Expand Down Expand Up @@ -307,11 +306,5 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
}
}

// We want to disable endpoint checks if there is only one endpoint
// We skip the case where it is idled, since we set NoHealthCheck above
if wasIdled == false && len(out) == 1 {
out[0].NoHealthCheck = true
}

return out
}
153 changes: 9 additions & 144 deletions pkg/router/template/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,15 @@ func TestHandleEndpoints(t *testing.T) {
Name: "foo/test", //service name from kapi.endpoints object
EndpointTable: []Endpoint{
{
ID: "ept:test:1.1.1.1:345",
IP: "1.1.1.1",
Port: "345",
NoHealthCheck: true,
ID: "ept:test:1.1.1.1:345",
IP: "1.1.1.1",
Port: "345",
},
},
},
},
{
name: "Endpoint mod (one ep, one address)",
name: "Endpoint mod",
eventType: watch.Modified,
endpoints: &kapi.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -300,143 +299,9 @@ func TestHandleEndpoints(t *testing.T) {
Name: "foo/test",
EndpointTable: []Endpoint{
{
ID: "pod:pod-1:test:2.2.2.2:8080",
IP: "2.2.2.2",
Port: "8080",
NoHealthCheck: true,
},
},
},
},
{
name: "Endpoint mod (second ep, one address each)",
eventType: watch.Modified,
endpoints: &kapi.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "test",
},
Subsets: []kapi.EndpointSubset{
{
Addresses: []kapi.EndpointAddress{{IP: "2.2.2.2", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
Ports: []kapi.EndpointPort{{Port: 8080}},
},
{
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}}},
Ports: []kapi.EndpointPort{{Port: 8081}},
},
},
},
expectedServiceUnit: &ServiceUnit{
Name: "foo/test",
EndpointTable: []Endpoint{
{
ID: "pod:pod-1:test:2.2.2.2:8080",
IP: "2.2.2.2",
Port: "8080",
NoHealthCheck: false,
},
{
ID: "pod:pod-2:test:3.3.3.3:8081",
IP: "3.3.3.3",
Port: "8081",
NoHealthCheck: false,
},
},
},
},
{
name: "Endpoint mod (one ep, two addresses)",
eventType: watch.Modified,
endpoints: &kapi.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "test",
},
Subsets: []kapi.EndpointSubset{
{
Addresses: []kapi.EndpointAddress{
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
{IP: "4.4.4.4", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-3"}},
},
Ports: []kapi.EndpointPort{{Port: 8080}},
},
},
},
expectedServiceUnit: &ServiceUnit{
Name: "foo/test",
EndpointTable: []Endpoint{
{
ID: "pod:pod-2:test:3.3.3.3:8080",
IP: "3.3.3.3",
Port: "8080",
NoHealthCheck: false,
},
{
ID: "pod:pod-3:test:4.4.4.4:8080",
IP: "4.4.4.4",
Port: "8080",
NoHealthCheck: false,
},
},
},
},
{
name: "Endpoint mod (one ep, two ports)",
eventType: watch.Modified,
endpoints: &kapi.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "test",
},
Subsets: []kapi.EndpointSubset{
{
Addresses: []kapi.EndpointAddress{
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
},
Ports: []kapi.EndpointPort{{Port: 8080}, {Port: 8081}},
},
},
},
expectedServiceUnit: &ServiceUnit{
Name: "foo/test",
EndpointTable: []Endpoint{
{
ID: "pod:pod-2:test:3.3.3.3:8080",
IP: "3.3.3.3",
Port: "8080",
NoHealthCheck: false,
},
{
ID: "pod:pod-2:test:3.3.3.3:8081",
IP: "3.3.3.3",
Port: "8081",
NoHealthCheck: false,
},
},
},
},
{
name: "Endpoint mod (back to one ep)",
eventType: watch.Modified,
endpoints: &kapi.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "foo",
Name: "test",
},
Subsets: []kapi.EndpointSubset{{
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
Ports: []kapi.EndpointPort{{Port: 8080}},
}},
},
expectedServiceUnit: &ServiceUnit{
Name: "foo/test",
EndpointTable: []Endpoint{
{
ID: "pod:pod-1:test:3.3.3.3:8080",
IP: "3.3.3.3",
Port: "8080",
NoHealthCheck: true,
ID: "pod:pod-1:test:2.2.2.2:8080",
IP: "2.2.2.2",
Port: "8080",
},
},
},
Expand All @@ -450,8 +315,8 @@ func TestHandleEndpoints(t *testing.T) {
Name: "test",
},
Subsets: []kapi.EndpointSubset{{
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
Ports: []kapi.EndpointPort{{Port: 8080}},
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3"}},
Ports: []kapi.EndpointPort{{Port: 0}},
}},
},
expectedServiceUnit: &ServiceUnit{
Expand Down

0 comments on commit 1d0ad23

Please sign in to comment.