Skip to content

Commit c9bb5d4

Browse files
authored
Merge pull request #5979 from Jefftree/sharding-post-alpha
KEP-5866: Update API details to match alpha implementation
2 parents 91cee5c + 02e5b77 commit c9bb5d4

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

keps/sig-api-machinery/5866-server-side-sharded-list-and-watch/README.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,17 @@ proposal will be implemented, this is the place to discuss them.
286286
### API Extensibility: Sharding Parameters
287287

288288
Clients will request shards via query parameters in their `LIST` and `WATCH` requests.
289-
The request must contain the field used to shard, as well as the start and end of the hash range.
290289

291-
Given that some Kubernetes features (like pagination) use individual, explicit query parameters,
292-
while others (like label selectors) provide a lightweight grammar for filter expressions, the exact
293-
syntax is currently under discussion. We will work with API Review to decide between two primary approaches:
290+
A dedicated `shardSelector` query parameter mapped to the `ShardSelector` field in
291+
`meta/v1.ListOptions`. This parameter accepts a lightweight CEL-based functional
292+
grammar, specifically utilizing a `shardRange()` function.
294293

295-
1. **Explicit Query Parameters**: Adding individual fields directly to `meta/v1.ListOptions`.
296-
- Example: `?shardKey=object.metadata.namespace&shardRange=0,100`
294+
**Syntax Details:**
295+
- `shardRange(fieldPath, hexStart, hexEnd)`
296+
- Bounds are defined as 64-bit strings with a `'0x'` prefix (e.g. `'0x0000000000000000'`, `'0x8000000000000000'`).
297+
- Supported field paths currently include `object.metadata.uid` and `object.metadata.namespace`.
297298

298-
2. **Lightweight Grammar**: Introducing a new `selector` expression parameter.
299-
- Example: `?selector=range(object.metadata.namespace, 0, 100)`
300-
- If this path is chosen, it could be implemented as a strict subset of CEL or a simple
301-
functional grammar.
302-
303-
Regardless of the syntax chosen, the parameters will be strongly typed internally on both the client side
299+
The parameters are strongly typed internally on both the client side
304300
(for syntactic correctness in `client-go`) and the server side (for validation and execution).
305301

306302
### Shard Key
@@ -331,14 +327,21 @@ reshard occurs.
331327

332328
### Client Request
333329

334-
Clients will append new parameters to their LIST and WATCH requests to subscribe to a specific
335-
slice of the stream.
330+
Clients will append the new parameter to their LIST and WATCH requests to subscribe
331+
to a specific slice of the stream.
336332

337333
**Example Request:**
338-
`GET /api/v1/pods?watch=true&selector=shardRange(object.metadata.uid, 0, 8)`
334+
`GET /api/v1/pods?watch=true&shardSelector=shardRange(object.metadata.uid, '0x0000000000000000', '0x8000000000000000')`
335+
336+
Clients can also specify multiple hash ranges simultaneously using the logical OR
337+
operator (`||`) implemented by the CEL evaluator.
339338

340-
- `selector`: Introduces a new query parameter to encapsulate expression-based selection logic.
341-
- `shardRange(...)`: A function within the selector grammar that specifies the field to hash (e.g., `object.metadata.uid`) and the start and end range (`start <= x < end`) of hash values this client desires. This provides a future-proof foundation without bloating `ListOptions` with multiple individual parameter fields.
339+
**Multiple Range Example:**
340+
`GET /api/v1/pods?watch=true&shardSelector=shardRange(object.metadata.uid, '0x0000000000000000', '0x8000000000000000') || shardRange(object.metadata.uid, '0x8000000000000000', '0x10000000000000000')`
341+
342+
- `shardSelector`: Introduces a new query parameter specifically for shard selection logic.
343+
- `shardRange(...)`: A CEL function that specifies the field to hash and the start
344+
(inclusive) / end (exclusive) hex bounds (`hexStart <= x < hexEnd`) of hash values.
342345

343346
### Server Design
344347

@@ -487,7 +490,7 @@ functionality is accessed.
487490

488491
#### Alpha
489492

490-
- Feature implemented behind `ShardableWatch` feature gate.
493+
- Feature implemented behind `ShardedListAndWatch` feature gate.
491494
- Basic unit and integration tests passing.
492495

493496
#### Beta
@@ -552,9 +555,16 @@ enhancement:
552555
-->
553556
- Clients must be updated to send the new parameters.
554557
- If a client sends sharding parameters to an old API server, the old server will ignore the unknown query parameters and send the full, un-sharded stream.
555-
- To allow clients to safely distinguish between a filtered stream and a full stream, the API Server will inject a new `Sharded: true` flag into the `ListMeta` of the initial `LIST` response (and the initial sync of a `WATCH`).
556-
- If a client requests a shard and observes `Sharded: true`, it can safely process all incoming events.
557-
- If the flag is missing or false, the client knows the server ignored the parameter and must perform client-side filtering (or fail) to drop objects outside its shard range.
558+
- To allow clients to safely distinguish between a filtered stream and a full stream,
559+
the API Server will return a new `ShardInfo` struct within the `ListMeta` of the
560+
initial `LIST` response (and initial sync of a `WATCH`).
561+
- The `ShardInfo` struct mirrors the applied selector back to the client via a `selector` string field.
562+
- If a client requests a shard and observes a matching `ShardInfo.selector`, it can
563+
safely construct partial lists, process incoming events, or merge responses
564+
across multiple shards.
565+
- If `ShardInfo` is absent, the client knows the server ignored the parameter
566+
and can take appropriate action to avoid breaking mutual exclusion like falling back to
567+
client-side sharding.
558568
- Clients can also deterministically check for server-side sharding support by querying the OpenAPI v3 discovery document for the presence of the sharding query parameters.
559569
- To enable safe client-side fallback, the hash algorithm and range evaluation logic will be placed in a common library (`k8s.io/apimachinery`).
560570

@@ -591,7 +601,7 @@ This section must be completed when targeting alpha to a release.
591601
###### How can this feature be enabled / disabled in a live cluster?
592602

593603
- [x] Feature gate (also fill in values in `kep.yaml`)
594-
- Feature gate name: `ShardableWatch`
604+
- Feature gate name: `ShardedListAndWatch`
595605
- Components depending on the feature gate: `kube-apiserver`
596606

597607
###### Does enabling the feature change any default behavior?
@@ -730,6 +740,8 @@ Latency for sharded watches should be comparable to standard watches.
730740
- [x] Metrics
731741
- Metric name: `apiserver_watch_shards_total`
732742
- Components exposing the metric: `kube-apiserver`
743+
- Metric name: `apiserver_watch_filtered_events_total`
744+
- Components exposing the metric: `kube-apiserver`
733745

734746
###### Are there any missing metrics that would be useful to have to improve observability of this feature?
735747

keps/sig-api-machinery/5866-server-side-sharded-list-and-watch/kep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ milestone:
3030
# The following PRR answers are required at alpha release
3131
# List the feature gate name and the components for which it must be enabled
3232
feature-gates:
33-
- name: ShardableWatch
33+
- name: ShardedListAndWatch
3434
components:
3535
- kube-apiserver
3636
disable-supported: true

0 commit comments

Comments
 (0)