Skip to content

Commit 1bae363

Browse files
Merge pull request #17077 from knobunc/fix/health-supression
Automatic merge from submit-queue. Fix the "supress health checks when only one backing service" logic This reverts commit 4833eb5 and then fixes the implementation. Previously we had attempted to suppress the health checks, but it was looking at the endpoints of the service, not the servers that back the route. The problem is that if we just look at endpoints, then if a route has two backing services, each with one endpoint, we would incorrectly suppress the health checks. Fixes bug 1507664 (https://bugzilla.redhat.com/show_bug.cgi?id=1507664)
2 parents 394c793 + 9835dca commit 1bae363

File tree

4 files changed

+191
-155
lines changed

4 files changed

+191
-155
lines changed

pkg/router/template/plugin.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
265265
wasIdled = true
266266
}
267267

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

271270
// Now build the actual endpoints we pass to the template
@@ -307,11 +306,5 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
307306
}
308307
}
309308

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

pkg/router/template/plugin_test.go

Lines changed: 9 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,15 @@ func TestHandleEndpoints(t *testing.T) {
275275
Name: "foo/test", //service name from kapi.endpoints object
276276
EndpointTable: []Endpoint{
277277
{
278-
ID: "ept:test:1.1.1.1:345",
279-
IP: "1.1.1.1",
280-
Port: "345",
281-
NoHealthCheck: true,
278+
ID: "ept:test:1.1.1.1:345",
279+
IP: "1.1.1.1",
280+
Port: "345",
282281
},
283282
},
284283
},
285284
},
286285
{
287-
name: "Endpoint mod (one ep, one address)",
286+
name: "Endpoint mod",
288287
eventType: watch.Modified,
289288
endpoints: &kapi.Endpoints{
290289
ObjectMeta: metav1.ObjectMeta{
@@ -300,143 +299,9 @@ func TestHandleEndpoints(t *testing.T) {
300299
Name: "foo/test",
301300
EndpointTable: []Endpoint{
302301
{
303-
ID: "pod:pod-1:test:2.2.2.2:8080",
304-
IP: "2.2.2.2",
305-
Port: "8080",
306-
NoHealthCheck: true,
307-
},
308-
},
309-
},
310-
},
311-
{
312-
name: "Endpoint mod (second ep, one address each)",
313-
eventType: watch.Modified,
314-
endpoints: &kapi.Endpoints{
315-
ObjectMeta: metav1.ObjectMeta{
316-
Namespace: "foo",
317-
Name: "test",
318-
},
319-
Subsets: []kapi.EndpointSubset{
320-
{
321-
Addresses: []kapi.EndpointAddress{{IP: "2.2.2.2", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
322-
Ports: []kapi.EndpointPort{{Port: 8080}},
323-
},
324-
{
325-
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}}},
326-
Ports: []kapi.EndpointPort{{Port: 8081}},
327-
},
328-
},
329-
},
330-
expectedServiceUnit: &ServiceUnit{
331-
Name: "foo/test",
332-
EndpointTable: []Endpoint{
333-
{
334-
ID: "pod:pod-1:test:2.2.2.2:8080",
335-
IP: "2.2.2.2",
336-
Port: "8080",
337-
NoHealthCheck: false,
338-
},
339-
{
340-
ID: "pod:pod-2:test:3.3.3.3:8081",
341-
IP: "3.3.3.3",
342-
Port: "8081",
343-
NoHealthCheck: false,
344-
},
345-
},
346-
},
347-
},
348-
{
349-
name: "Endpoint mod (one ep, two addresses)",
350-
eventType: watch.Modified,
351-
endpoints: &kapi.Endpoints{
352-
ObjectMeta: metav1.ObjectMeta{
353-
Namespace: "foo",
354-
Name: "test",
355-
},
356-
Subsets: []kapi.EndpointSubset{
357-
{
358-
Addresses: []kapi.EndpointAddress{
359-
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
360-
{IP: "4.4.4.4", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-3"}},
361-
},
362-
Ports: []kapi.EndpointPort{{Port: 8080}},
363-
},
364-
},
365-
},
366-
expectedServiceUnit: &ServiceUnit{
367-
Name: "foo/test",
368-
EndpointTable: []Endpoint{
369-
{
370-
ID: "pod:pod-2:test:3.3.3.3:8080",
371-
IP: "3.3.3.3",
372-
Port: "8080",
373-
NoHealthCheck: false,
374-
},
375-
{
376-
ID: "pod:pod-3:test:4.4.4.4:8080",
377-
IP: "4.4.4.4",
378-
Port: "8080",
379-
NoHealthCheck: false,
380-
},
381-
},
382-
},
383-
},
384-
{
385-
name: "Endpoint mod (one ep, two ports)",
386-
eventType: watch.Modified,
387-
endpoints: &kapi.Endpoints{
388-
ObjectMeta: metav1.ObjectMeta{
389-
Namespace: "foo",
390-
Name: "test",
391-
},
392-
Subsets: []kapi.EndpointSubset{
393-
{
394-
Addresses: []kapi.EndpointAddress{
395-
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
396-
},
397-
Ports: []kapi.EndpointPort{{Port: 8080}, {Port: 8081}},
398-
},
399-
},
400-
},
401-
expectedServiceUnit: &ServiceUnit{
402-
Name: "foo/test",
403-
EndpointTable: []Endpoint{
404-
{
405-
ID: "pod:pod-2:test:3.3.3.3:8080",
406-
IP: "3.3.3.3",
407-
Port: "8080",
408-
NoHealthCheck: false,
409-
},
410-
{
411-
ID: "pod:pod-2:test:3.3.3.3:8081",
412-
IP: "3.3.3.3",
413-
Port: "8081",
414-
NoHealthCheck: false,
415-
},
416-
},
417-
},
418-
},
419-
{
420-
name: "Endpoint mod (back to one ep)",
421-
eventType: watch.Modified,
422-
endpoints: &kapi.Endpoints{
423-
ObjectMeta: metav1.ObjectMeta{
424-
Namespace: "foo",
425-
Name: "test",
426-
},
427-
Subsets: []kapi.EndpointSubset{{
428-
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
429-
Ports: []kapi.EndpointPort{{Port: 8080}},
430-
}},
431-
},
432-
expectedServiceUnit: &ServiceUnit{
433-
Name: "foo/test",
434-
EndpointTable: []Endpoint{
435-
{
436-
ID: "pod:pod-1:test:3.3.3.3:8080",
437-
IP: "3.3.3.3",
438-
Port: "8080",
439-
NoHealthCheck: true,
302+
ID: "pod:pod-1:test:2.2.2.2:8080",
303+
IP: "2.2.2.2",
304+
Port: "8080",
440305
},
441306
},
442307
},
@@ -450,8 +315,8 @@ func TestHandleEndpoints(t *testing.T) {
450315
Name: "test",
451316
},
452317
Subsets: []kapi.EndpointSubset{{
453-
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
454-
Ports: []kapi.EndpointPort{{Port: 8080}},
318+
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3"}},
319+
Ports: []kapi.EndpointPort{{Port: 0}},
455320
}},
456321
},
457322
expectedServiceUnit: &ServiceUnit{

pkg/router/template/template_helper.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,28 @@ func processEndpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit, action
157157
}
158158

159159
func endpointsForAlias(alias ServiceAliasConfig, svc ServiceUnit) []Endpoint {
160-
if len(alias.PreferPort) == 0 {
160+
if len(alias.PreferPort) == 0 && len(svc.EndpointTable) != 1 {
161+
// We can skip the work. They are selecting everything, and since they don't have one endpoint,
162+
// we can't disable the health checks. So we can just use their list.
161163
return svc.EndpointTable
162164
}
165+
163166
endpoints := make([]Endpoint, 0, len(svc.EndpointTable))
164-
for i := range svc.EndpointTable {
165-
endpoint := svc.EndpointTable[i]
166-
if endpoint.PortName == alias.PreferPort || endpoint.Port == alias.PreferPort {
167+
for _, endpoint := range svc.EndpointTable {
168+
// Filter the list:
169+
// - If PreferPort length is 0, match everything
170+
// - Otherwise, if the PortName or Port matches PreferPort, then we have a match
171+
if len(alias.PreferPort) == 0 || endpoint.PortName == alias.PreferPort || endpoint.Port == alias.PreferPort {
167172
endpoints = append(endpoints, endpoint)
168173
}
169174
}
175+
176+
// We want to disable endpoint checks if there is only one endpoint since there's no point in
177+
// testing and removing it from the set ahead of time since there are no other eps to replace it.
178+
if len(endpoints) == 1 {
179+
endpoints[0].NoHealthCheck = true
180+
}
181+
170182
return endpoints
171183
}
172184

0 commit comments

Comments
 (0)