Skip to content

[rds.kubernetes] Add HTTPRoute (Gateway API) target discovery - #1424

Merged
manugarg merged 6 commits into
mainfrom
k8s-httproute-discovery
Sep 13, 2026
Merged

manugarg merged 6 commits into
mainfrom
k8s-httproute-discovery

Conversation

@manugarg

@manugarg manugarg commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds Kubernetes target discovery for Gateway API HTTPRoute resources, analogous to the existing Ingress support. Closes #1409.

What it does

  • New http_routes resource type for the k8s targets provider.
  • Each HTTPRoute is expanded into one RDS resource per (hostname x match path), mirroring how ingresses are expanded:
  • Hostnames come from spec.hostnames (Gateway API has no rule-level hostnames).
  • Routes without hostnames (they inherit them from the Gateway listener) and wildcard hostnames (e.g. *.example.com) produce no resources, since there is no specific host to probe.
  • RegularExpression path matches are skipped, as they don't name a specific URL.
  • If the route has its own relative_url label, paths are not expanded: one resource per hostname, named <route>_<host>.
  • Rules that expand to the same (hostname, path), e.g. rules differing only in header or method matches, produce a single resource.

Note on the target IP

Unlike Ingress, an HTTPRoute does not carry a load balancer IP in its status (the address lives on the parent Gateway). This change uses the route hostname as the target IP; the probe resolves it via DNS, and the fqdn label drives the Host header / SNI. Resolving the parent Gateway.status.addresses for a real IP is a possible follow-up, as is using the route's status conditions as a readiness signal.

Requires the Gateway API CRDs to be installed in the cluster.

Config

targets {
  k8s {
    http_routes: ".*"
  }
}

Tests

  • httproutes_test.go + testdata/httproutes.json cover parsing, listing, and name/label/namespace filtering, skipping of hostname-less and wildcard routes and regex paths, the relative_url label override, and deduplication of identical (hostname, path) pairs.
  • targets/k8s_test.go covers the http_routes config.

@wingsofovnia

Copy link
Copy Markdown

Thank you for this contribution! Support of GRPCRoute would also be great. It's the same exact structure (for what is relevant here) 🙏

@manugarg

Copy link
Copy Markdown
Contributor Author

Sorry for the delay here. I was waiting for the refactor that I just merged through #1486 before adding more resource types.

@manugarg
manugarg force-pushed the k8s-httproute-discovery branch from 8935628 to bf90138 Compare September 12, 2026 06:26
@manugarg

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #1486 (generic resourceLister) and #1485 have landed, and converted the lister to the new pattern.

httproutes.go goes from 253 to 152 lines. What went away was the fifth copy of the shared boilerplate — the httpRoutesLister struct, httpRoutesURL, listResources, parseHTTPRoutesJSON, expand, and the refresh goroutine. What stayed is the part that's actually about HTTPRoute: the route types and resources().

Worth noting the rebase itself was clean and the result compiled and passed tests with the old pattern still in place — the additions never textually overlapped what #1486 rewrote. So nothing would have flagged that this was still a fifth copy; the conversion had to be deliberate.

Three things it inherits for free:

  • expand() keeps the last good result when a refresh fails. The version in this PR had the same fall-through that emptied the cache on any API error.
  • The refresh loop no longer calls the deprecated rand.Seed, and the stale "gceInstances / GCE API" comment is gone with it.
  • A name in the resource path (k8s://httproutes/my-route) selects a single route, consistent with every other type.

One judgment call worth a look. HTTPRoute filters name and labels on the expanded resources rather than on the route object, which is what this PR already did and matches ingresses — derived names and per-resource fqdn/relative_url labels would be unselectable otherwise.

The subtlety is the fallback resource for a route with no hostnames. It has to be chosen before filtering, otherwise a route whose resources are all filtered out reappears under its bare name. The naive conversion gets this wrong, and this PR's own tests catch it — name filter for host regex picks up a spurious rule-host-route. Kept the original ordering and added a comment saying why.

Also added httproutes to TestListerAPIPaths, so the gateway.networking.k8s.io prefix is pinned like the other four. Package coverage 83.9% -> 84.8%. go build ./... and go test -race ./internal/rds/... ./targets/... pass.

Discover Gateway API HTTPRoute objects as targets, expanding each route
into one resource per (hostname, path) pair the way ingresses are
expanded.

Unlike an ingress, an HTTPRoute carries no load balancer IP in its
status: the address belongs to the parent Gateway, which is not resolved
here. The route hostname is used as the target IP and exposed as the
fqdn label, so probes resolve it via DNS and send the right Host header.

Built on the generic resourceLister, so the new type is an info struct
with metadata() and resources() plus a constructor naming the kind and
the gateway.networking.k8s.io API prefix. The URL builder, JSON parsing,
refresh loop and filtering are all shared.

Note that the fallback resource for a route with no hostnames is chosen
before the name and labels filters are applied, so that a route whose
resources are all filtered out doesn't reappear under its bare name.
Route hostnames are the only thing we can probe: routes without them
inherit hostnames from the Gateway listener, and wildcard hostnames
don't name a specific host. Previously these produced targets that could
never succeed (no IP, or an IP of "*.example.com").
HTTPRouteRule has no hostnames field in the Gateway API; hostnames exist
only at the route level (spec.hostnames). The override logic was dead
code, and the test fixture modeled an object the API server never
returns.
Use kMetadata.resourceLabels(), as the other kinds do since #1489.
@manugarg
manugarg force-pushed the k8s-httproute-discovery branch from e8dae98 to bceb1ad Compare September 13, 2026 05:13
- Rules that differ only in header or method matches expand to the same
  (hostname, path) pair; emit that resource once instead of relying on
  the RDS client to drop duplicates with a warning on every refresh.
- Add an http_routes case to Test_parseConfig.
- Note that HTTPRoute discovery needs the Gateway API CRDs installed.
- RegularExpression path matches don't name a specific URL, so probing
  them literally always fails. Skip them.
- If the route has its own relative_url label, every resource would probe
  that URL, so emit one resource per hostname instead of one per path.
- Reflow the Target Labels paragraph.
@manugarg
manugarg force-pushed the k8s-httproute-discovery branch from a26bc9d to 83dc70d Compare September 13, 2026 06:08
@manugarg manugarg changed the title [targets.k8s] Add HTTPRoute (Gateway API) target discovery [rds.kubernetes] Add HTTPRoute (Gateway API) target discovery Sep 13, 2026
@manugarg
manugarg merged commit d18af84 into main Sep 13, 2026
13 checks passed
@manugarg
manugarg deleted the k8s-httproute-discovery branch September 16, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes target discovery: support for the Gateway API (HTTPRoute resource)

2 participants