Skip to content

Commit 2bf6e39

Browse files
committed
Streaming lists documentation
1 parent bd456cf commit 2bf6e39

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

content/en/docs/reference/command-line-tools-reference/feature-gates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ For a reference to old feature gates that are removed, please refer to
205205
| `UserNamespacesStatelessPodsSupport` | `false` | Alpha | 1.25 | |
206206
| `ValidatingAdmissionPolicy` | `false` | Alpha | 1.26 | |
207207
| `VolumeCapacityPriority` | `false` | Alpha | 1.21 | - |
208+
| `WatchList` | false | Alpha | 1.27 | |
208209
| `WinDSR` | `false` | Alpha | 1.14 | |
209210
| `WinOverlay` | `false` | Alpha | 1.14 | 1.19 |
210211
| `WinOverlay` | `true` | Beta | 1.20 | |
@@ -729,6 +730,7 @@ Each feature gate is designed for enabling/disabling a specific feature:
729730
- `VolumeCapacityPriority`: Enable support for prioritizing nodes in different
730731
topologies based on available PV capacity.
731732
- `WatchBookmark`: Enable support for watch bookmark events.
733+
- `WatchList` : Enable support for [streaming initial state of objects in watch requests](/docs/reference/using-api/api-concepts/#streaming-lists).
732734
- `WinDSR`: Allows kube-proxy to create DSR loadbalancers for Windows.
733735
- `WinOverlay`: Allows kube-proxy to run in overlay mode for Windows.
734736
- `WindowsHostNetwork`: Enables support for joining Windows containers to a hosts' network namespace.

content/en/docs/reference/using-api/api-concepts.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ For subscribing to collections, Kubernetes client libraries typically offer some
195195
of standard tool for this **list**-then-**watch** logic. (In the Go client library,
196196
this is called a `Reflector` and is located in the `k8s.io/client-go/tools/cache` package.)
197197

198-
### Watch bookmarks
198+
### Watch bookmarks {#watch-bookmarks}
199199

200200
To mitigate the impact of short history window, the Kubernetes API provides a watch
201201
event named `BOOKMARK`. It is a special kind of event to mark that all changes up
@@ -226,6 +226,64 @@ As a client, you can request `BOOKMARK` events by setting the
226226
assume bookmarks are returned at any specific interval, nor can clients assume that
227227
the API server will send any `BOOKMARK` event even when requested.
228228

229+
## Streaming lists
230+
231+
{{< feature-state for_k8s_version="v1.27" state="alpha" >}}
232+
233+
On large clusters, retrieving the collection of some resource types may result in
234+
a significant increase of resource usage (primarily RAM) on the control plane.
235+
In order to alleviate its impact and simplify the user experience of the **list** + **watch**
236+
pattern, Kubernetes v1.27 introduces as an alpha feature the support
237+
for requesting the initial state (previously requested via the **list** request) as part of
238+
the **watch** request.
239+
240+
Provided that the `WatchList` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
241+
is enabled, this can be achieved by specifying `sendInitialEvents=true` as query string parameter
242+
in a **watch** request. If set, the API server starts the watch stream with synthetic init
243+
events (of type `ADDED`) to build the whole state of all existing objects followed by a
244+
[`BOOKMARK` event](/docs/reference/using-api/api-concepts/#watch-bookmarks)
245+
(if requested via `allowWatchBookmarks=true` option). The bookmark event includes the resource version
246+
to which is synced. After sending the bookmark event, the API server continues as for any other **watch**
247+
request.
248+
249+
When you set `sendInitialEvents=true` in the query string, Kubernetes also requires that you set
250+
`resourceVersionMatch` to `NotOlderThan` value.
251+
If you provided `resourceVersion` in the query string without providing a value or don't provide
252+
it at all, this is interpreted as a request for _consistent read_;
253+
the bookmark event is sent when the state is synced at least to the moment of a consistent read
254+
from when the request started to be processed. If you specify `resourceVersion` (in the query string),
255+
the bookmark event is sent when the state is synced at least to the provided resource version.
256+
257+
### Example {#example-streaming-lists}
258+
259+
An example: you want to watch a collection of Pods. For that collection, the current resource version
260+
is 10245 and there are two pods: `foo` and `bar`. Then sending the following request (explicitly requesting
261+
_consistent read_ by setting empty resource version using `resourceVersion=`) could result
262+
in the following sequence of events:
263+
264+
```console
265+
GET /api/v1/namespaces/test/pods?watch=1&sendInitialEvents=true&allowWatchBookmarks=true&resourceVersion=&resourceVersionMatch=NotOlderThan
266+
---
267+
200 OK
268+
Transfer-Encoding: chunked
269+
Content-Type: application/json
270+
271+
{
272+
"type": "ADDED",
273+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "8467", "name": "foo"}, ...}
274+
}
275+
{
276+
"type": "ADDED",
277+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "5726", "name": "bar"}, ...}
278+
}
279+
{
280+
"type": "BOOKMARK",
281+
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "10245"} }
282+
}
283+
...
284+
<followed by regular watch stream starting from resourceVersion="10245">
285+
```
286+
229287
## Retrieving large results sets in chunks
230288

231289
{{< feature-state for_k8s_version="v1.9" state="beta" >}}

0 commit comments

Comments
 (0)