Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the documented behavior and includes broad test coverage for relevant success and failure paths.
Review effort: Balanced
Findings: None
What changed in this PR
Adds explicit multi-cluster selection for Kubernetes-discovered upstreams while preserving existing discovery behavior.
Changes:
- Adds
discovery_args.cluster_idsschema validation and service-name checks. - Merges and deduplicates endpoints from selected clusters with version-aware caching.
- Adds bilingual documentation and comprehensive integration tests.
| File | Description |
|---|---|
apisix/discovery/kubernetes/init.lua |
Resolves and merges endpoints from selected clusters. |
apisix/schema_def.lua |
Defines the cluster_ids schema. |
apisix/upstream.lua |
Rejects incompatible prefixed service names. |
docs/en/latest/discovery/kubernetes.md |
Documents the feature in English. |
docs/zh/latest/discovery/kubernetes.md |
Documents the feature in Chinese. |
t/kubernetes/discovery/kubernetes5.t |
Tests selection, caching, deduplication, validation, and proxying. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
nic-6443
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
In multi-cluster mode, Kubernetes service discovery can only resolve a
service_nameagainst one cluster (id/namespace/name:port_name). This PR lets an upstream pick several clusters explicitly and get the union of their endpoints:{ "discovery_type": "kubernetes", "service_name": "default/plat-dev:port", "discovery_args": { "cluster_ids": ["release", "staging"] } }Behaviour:
idfrom thediscovery.kubernetesarray), cached per cluster endpoint version, so endpoint changes in those clusters keep refreshing the upstream. The samehost:portfound in more than one cluster is used once.discovery_typeis loaded and exportscheck_discovery_args(discovery_args, service_name, in_dp),check_upstream_confcalls it and returns its error. Kubernetes discovery implements it:cluster_ids,service_namemust benamespace/name:port_name; acluster_id/namespace/name:port_namevalue is rejected and the error shows it.in_dp),cluster_idsis rejected when kubernetes discovery is configured as a single cluster, and ids that are not indiscovery.kubernetesof that instance are rejected with one error listing all of them.service_namewith a cluster id prefix reaches the discovery module anyway (for example in a stream route, which the Admin API does not pass throughcheck_upstream_conf), it logs an error and returns no nodes.cluster_idshas no cluster to match, so the upstream gets no nodes and an error is logged.cluster_ids, the existing behaviour is unchanged (namespace/name:port_namein single-cluster mode,id/namespace/name:port_namein multi-cluster mode).cluster_idsis added todiscovery_argsin the upstream schema next to the existingnamespace_id/group_name, as a non-empty array of unique strings.Tests:
t/kubernetes/discovery/kubernetes5.tcovers selection against the kind cluster (listed vs unlisted clusters, unknown ids, endpoint updates), the union and dedup with fixed endpoint data, proxied requests through HTTP routes and a stream route withcluster_ids(the stream case also checks the union from the-streamdicts), single-cluster mode, and the data plane config-load path.t/discovery/kubernetes_cluster_ids.tcovers the Admin API validation (unknown ids, prefix, single-cluster configuration, schema errors, inline upstreams in routes and services).Which issue(s) this PR fixes:
None.
Checklist