Skip to content

[BUG] Endpoint updates can rewrite multi-port service routes to the wrong port #6493

Description

@Aias00

Current Behavior

When Kubernetes Endpoints change, EndpointsReconciler rebuilds upstream handles for all ingresses that reference the service using the first TCP port from each endpoint subset.

CoreV1EndpointPort endpointPort = ports.stream()
        .filter(coreV1EndpointPort -> "TCP".equals(coreV1EndpointPort.getProtocol()))
        .findFirst()
        .orElseThrow(...);

The service-to-ingress cache only stores namespace/service to ingress names, not the backend service port selected by each ingress. updateSelectors(...) then applies the same rebuilt upstream handle to all cached divide/websocket selectors for that service.

If a service exposes multiple TCP ports and an ingress selects a non-first port, or multiple ingresses select different ports on the same service, an endpoint update can rewrite selectors to the wrong upstream port.

Expected Behavior

Endpoint reconciliation should preserve the service port selected by each ingress backend instead of using the first TCP endpoint port for every selector associated with the service.

Impact

For multi-port services, endpoint updates can silently route divide/websocket traffic to the wrong upstream port.

Code Location

  • shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/reconciler/EndpointsReconciler.java
    • endpointAddresses() picks the first TCP port from the endpoint subset.
    • updateSelectors() applies the rebuilt handle to all selectors associated with the service.
  • shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/cache/ServiceIngressCache.java
    • cache key does not retain the ingress backend service port.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions