Skip to content

Commit 6d02b4e

Browse files
committed
BUG/MINOR: Fix an incorrect lookup of the Endpoints corresponding to a
Service Port When looking to the Endpoints corresponding to a service Port we used to match the Service Port (Service.ports[].Port) against the Endpoints Port (TargetPort) which is incorrect because they are not necessarily the same. An example of ServicePort config that may trigger this bug: ports: - name: http port: 8080 protocol: TCP targetPort: 80 - name: http-alt port: 8888 protocol: TCP targetPort: 8080 If an ingress rule is using the "http" service port, the controller may pick the "http-alt" endpoints (instead of "http" ones) because http.8080 == http-atl.8080 The fix is to simply check if EndpointPort.Name == Service.ports[].Name when looking for corresponding endpoints.
1 parent 9e26246 commit 6d02b4e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

controller/service/endpoints.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,9 @@ func (s *SvcContext) getEndpoints(k8s store.K8s) (endpoints *store.PortEndpoints
169169
}
170170
return nil, fmt.Errorf("no Endpoints for service '%s'", s.service.Name)
171171
}
172-
sp := s.path.SvcPortResolved
173-
if sp != nil {
174-
for portName, endpoints := range e.Ports {
175-
if portName == sp.Name || endpoints.Port == sp.Port {
176-
return endpoints, nil
177-
}
178-
}
172+
svcPort := s.path.SvcPortResolved
173+
if svcPort != nil && e.Ports[svcPort.Name] != nil {
174+
return e.Ports[svcPort.Name], nil
179175
}
180176
if s.path.SvcPortString != "" {
181177
return nil, fmt.Errorf("no matching endpoints for service '%s' and port '%s'", s.service.Name, s.path.SvcPortString)

0 commit comments

Comments
 (0)