AlinsRan opened a new pull request, #13991:
URL: https://github.com/apache/apisix/pull/13991

   ### Description
   
   In multi-cluster mode, Kubernetes service discovery can only resolve a 
`service_name` against one cluster (`id/namespace/name:port_name`). This PR 
lets an upstream pick several clusters explicitly and get the union of their 
endpoints:
   
   ```json
   {
       "discovery_type": "kubernetes",
       "service_name": "default/plat-dev:port",
       "discovery_args": {
           "cluster_ids": ["release", "staging"]
       }
   }
   ```
   
   Behaviour:
   
   - The nodes are the union of the matching endpoints in the listed clusters 
(an `id` from the `discovery.kubernetes` array), cached per cluster endpoint 
version, so endpoint changes in those clusters keep refreshing the upstream. 
The same `host:port` found in more than one cluster is used once.
   - Clusters that are not listed, including clusters added to the 
configuration later, never contribute nodes.
   - If none of the listed clusters has matching endpoints, the upstream goes 
through the existing "no valid upstream node" path. There is no fallback to 
other clusters.
   - An unknown cluster id is logged as an error and skipped at runtime. The 
Admin API has no hook that validates `discovery_args` against the loaded 
discovery configuration (`check_upstream_conf` only runs the schema and 
field-level checks, and the discovery modules only expose `nodes` / 
`init_worker` / `dump_data`), so it is not checked when the configuration is 
submitted.
   - With `cluster_ids`, `service_name` must not carry a cluster id prefix. The 
Admin API rejects `cluster_id/namespace/name:port_name` in that case, and the 
discovery module logs an error and returns no nodes if such a configuration 
arrives another way.
   - In single-cluster mode, `cluster_ids` has no cluster to match, so the 
upstream gets no nodes and an error is logged.
   - Without `cluster_ids`, the existing behaviour is unchanged 
(`namespace/name:port_name` in single-cluster mode, 
`id/namespace/name:port_name` in multi-cluster mode).
   
   `cluster_ids` is added to `discovery_args` in the upstream schema next to 
the existing `namespace_id` / `group_name`, as a non-empty array of unique 
strings.
   
   Tests: `t/kubernetes/discovery/kubernetes5.t` covers selection against the 
kind cluster (listed vs unlisted clusters, unknown ids, endpoint updates), the 
union and dedup with fixed endpoint data, a proxied request through a route 
with `cluster_ids`, single-cluster mode, and the Admin API validation.
   
   #### Which issue(s) this PR fixes:
   
   Fixes #
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [x] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, 
please discuss on the [APISIX mailing 
list](https://github.com/apache/apisix/tree/master#community) first)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to