Skip to content

Commit

Permalink
BUG/MINOR: Fix an incorrect lookup of the Endpoints corresponding to a
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mo3m3n committed Jan 13, 2022
1 parent 9e26246 commit 6d02b4e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions controller/service/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ func (s *SvcContext) getEndpoints(k8s store.K8s) (endpoints *store.PortEndpoints
}
return nil, fmt.Errorf("no Endpoints for service '%s'", s.service.Name)
}
sp := s.path.SvcPortResolved
if sp != nil {
for portName, endpoints := range e.Ports {
if portName == sp.Name || endpoints.Port == sp.Port {
return endpoints, nil
}
}
svcPort := s.path.SvcPortResolved
if svcPort != nil && e.Ports[svcPort.Name] != nil {
return e.Ports[svcPort.Name], nil
}
if s.path.SvcPortString != "" {
return nil, fmt.Errorf("no matching endpoints for service '%s' and port '%s'", s.service.Name, s.path.SvcPortString)
Expand Down

0 comments on commit 6d02b4e

Please sign in to comment.