Skip to content

Backport of Abhishek/fix api gw peering into release/2.0.x#23500

Merged
LordAbhishek merged 1 commit intorelease/2.0.xfrom
backport/abhishek/api-gateway-peering/overly-helped-coyote
Apr 23, 2026
Merged

Backport of Abhishek/fix api gw peering into release/2.0.x#23500
LordAbhishek merged 1 commit intorelease/2.0.xfrom
backport/abhishek/api-gateway-peering/overly-helped-coyote

Conversation

@hc-github-team-consul-core
Copy link
Copy Markdown
Collaborator

Backport

This PR is auto-generated from #23454 to be assessed for backporting due to the inclusion of the label backport/2.0.

The below text is copied from the body of the original PR.


This PR adds api gateway peering unit test cases and fixes couple of issues discussed below with “api gateway when operating in peering”.
Please note: This PR merges 3 other small PRs.
#23369
#23370
#23371

Issues details (Theoretically): API Gateway issue with peering and fix.docx

Details:

  1. Whenever we generate the endpoints config for api-gateway, within makeUpstreamLoadAssignmentForPeerService (xds/endpoints.go), it always fetch local_mesh_gateway_endpoint only from connect-proxy, instead of api-gateway cfgSnap.
    localGw, ok := cfgSnap.ConnectProxy.WatchedLocalGWEndpoints.Get(cfgSnap.Locality.String()).

    If not fixed, api-gateway’s cluster for peering will always endup with no endpoints, when meshGatewayConfig.Mode is local.

    Fixed it to fetch the endpoints based on cfgSnap kind. PR

  2. Whenever we generate the endpoint config for api-gateway, within endpointsFromDiscoveryChain (xds/endpoints.go), it fetches meshGatewayConfig to configure endpoints, if it needs to point to local meshGateway or remote meshGateway.
    Here also, this method always fetches meshGatewayConfig.Mode from connect-proxy, instead of api-gateway. So, mgwMode is always nil and nil defaults to remote meshGatewayConfig.Mode.
    So, even if we configure the mesh-gateway to local, it will always fallback to remote.

    Fixed it to fetch the meshGatewayConfig based on cfgSnap kind. PR

  3. In continuation of issue 2, where we have to fetch the meshGatewayConfig for api-gateway, we never have had the meshGatewayConfig in api-gateway upstreams. 

    Found that handleRouteConfigUpdate (proxycfg/api_gateway.go) which updates the upstreams for api-gateway, was skipping to propagate meshGatewayConfig to upstreams. 

    Fixed it by adding meshGatewayConfig within upstream object. PR

  4. Whenever we generate the cluster config for api-gateway, within makeUpstreamClustersForDiscoveryChain (xds/clusters.go), it always generates the cluster without endpoints.
    As we know that whenever any service upstream endpoints is hostname, we have to send it via clusters config to CDS, because envoy is not able to resolve hostnames as EDS. 

    If not fixed, this would results envoy config without endpoints for some clusters (those whose upstream are of hostname type).

    Fixed it to generate cluster based on upstream endpoint type as done for connect proxy or mesh gateway. PR

How the fix is tested:

Unit test cases:
$ go test ./agent/xds -run 'TestAllResourcesFromSnapshot/.*/api-gateway-with-peers-mesh-mode-(local|remote)-and-upstream-is-(hostname|static)' -count=1 -update

ok github.com/hashicorp/consul/agent/xds 0.491s
$ go test ./agent/xds
ok github.com/hashicorp/consul/agent/xds 1.924s
$ go test ./agent/proxycfg
ok github.com/hashicorp/consul/agent/proxycfg 5.105s

Consul-k8s acceptance tests:

consul-ent PR (same as this one):
Ran the consul-k8s workflow with the patched consul-ent image.
All peering test ran fine on both EKS and Kind.
Kind test: https://github.com/hashicorp/consul-k8s-workflows/actions/runs/22376072101
EKS test: https://github.com/hashicorp/consul-k8s-workflows/actions/runs/22376066354


Overview of commits

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved Consul Bot automated PR

@github-actions github-actions Bot added theme/telemetry Anything related to telemetry or observability theme/envoy/xds Related to Envoy support labels Apr 22, 2026
@LordAbhishek LordAbhishek enabled auto-merge (squash) April 23, 2026 06:43
Copy link
Copy Markdown
Contributor

@santoshpulluri santoshpulluri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport changes are looking good

@LordAbhishek LordAbhishek merged commit 14f4a64 into release/2.0.x Apr 23, 2026
114 of 115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme/envoy/xds Related to Envoy support theme/telemetry Anything related to telemetry or observability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants