Skip to content

Commit b48397c

Browse files
jpbetzlmktfy
andauthored
Document PartialObjectMetadata accept param (#51994)
* Document PartialObjectMetadata accept param * Apply feedback * Apply suggestions from sftim Co-authored-by: Tim Bannister <[email protected]> --------- Co-authored-by: Tim Bannister <[email protected]>
1 parent f370c56 commit b48397c

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

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

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ For example:
191191
}
192192
```
193193

194+
You can also request [table](#table-fetches) and [metadata-only](#metadata-only-fetches)
195+
representations of this encoding.
196+
194197
### YAML resource encoding {#yaml-encoding}
195198

196199
Kubernetes also supports the [`application/yaml`](https://www.rfc-editor.org/rfc/rfc9512.html)
@@ -233,6 +236,9 @@ For example:
233236
234237
```
235238

239+
You can also request [table](#table-fetches) and [metadata-only](#metadata-only-fetches)
240+
representations of this encoding.
241+
236242
### Kubernetes Protobuf encoding {#protobuf-encoding}
237243

238244
Kubernetes uses an envelope wrapper to encode [Protobuf](https://protobuf.dev/) responses.
@@ -322,6 +328,9 @@ to alter the serialization format in an incompatible way and will do so by chang
322328
the prefix.
323329
{{< /note >}}
324330

331+
You can also request [table](#table-fetches) and [metadata-only](#metadata-only-fetches)
332+
representations of this encoding.
333+
325334
#### Compatibility with Kubernetes Protobuf {#protobuf-encoding-compatibility}
326335

327336
Not all API resource types support Kubernetes' Protobuf encoding; specifically, Protobuf isn't
@@ -367,6 +376,9 @@ In addition to the existing `application/apply-patch+yaml` media type for YAML-e
367376
is no supported CBOR equivalent for `application/json-patch+json` or `application/merge-patch+json`,
368377
or `application/strategic-merge-patch+json`.
369378

379+
You can also request [table](#table-fetches) and [metadata-only](#metadata-only-fetches)
380+
representations of this encoding.
381+
370382
## Efficient detection of changes
371383

372384
The Kubernetes API allows clients to make an initial request for an object or a
@@ -765,7 +777,7 @@ collections that might be of different kinds of object. Avoid depending on
765777
`kind: List` in automation or other code.
766778
{{< /note >}}
767779

768-
## Receiving resources as Tables
780+
## Table fetches
769781

770782
When you run `kubectl get`, the default output format is a simple tabular
771783
representation of one or more instances of a particular resource type. In the past,
@@ -845,6 +857,102 @@ extensions, you should make requests that specify multiple content types in the
845857
Accept: application/json;as=Table;g=meta.k8s.io;v=v1, application/json
846858
```
847859

860+
If the client indicates it only accepts `...;as=Table;g=meta.k8s.io;v=v1`, servers
861+
that don't support table responses will return a 406 error code.
862+
863+
If falling back to full objects in that case is desired, clients can add `,application/json`
864+
(or any other supported encoding) to their Accept header, and handle either
865+
table or full objects in the response:
866+
867+
```http
868+
Accept: application/json;as=Table;g=meta.k8s.io;v=v1,application/json`
869+
```
870+
871+
For more information on content type negotiation, see the
872+
[MDN Content Negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation).
873+
874+
## Metadata-only fetches
875+
876+
To request partial object metadata, you can request metadata only responses in the `Accept`
877+
header. The Kubernetes API implements a variation on HTTP content type negotiation.
878+
As a client, you can provide an `Accept` header with the desired media type,
879+
along with parameters that indicate you want only metadata.
880+
For example: `Accept: application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1`
881+
for JSON.
882+
883+
For example, to list all of the pods in a cluster, across all namespaces, but returning only the metadata for each pod:
884+
885+
```http
886+
GET /api/v1/pods
887+
Accept: application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1
888+
---
889+
200 OK
890+
Content-Type: application/json
891+
892+
{
893+
"kind": "PartialObjectMetadataList",
894+
"apiVersion": "meta.k8s.io/v1",
895+
"metadata": {
896+
"resourceVersion": "...",
897+
},
898+
"items": [
899+
{
900+
"apiVersion": "meta.k8s.io/v1",
901+
"kind": "PartialObjectMetadata",
902+
"metadata": {
903+
"name": "pod-1",
904+
...
905+
}
906+
},
907+
{
908+
"apiVersion": "meta.k8s.io/v1",
909+
"kind": "PartialObjectMetadata",
910+
"metadata": {
911+
"name": "pod-2",
912+
...
913+
}
914+
}
915+
]
916+
}
917+
```
918+
919+
For a request for a collection, the API server returns a PartialObjectMetadataList.
920+
For a request for a single object, the API server returns a PartialObjectMetadata
921+
representation of the
922+
object. In both cases, the returned objects only contain the `metadata` field.
923+
The `spec` and `status` fields are omitted.
924+
925+
This feature is useful for clients that only need to check for the existence of
926+
an object, or that only need to read its metadata. It can significantly reduce
927+
the size of the response from the API server.
928+
929+
You can request a metadata-only fetch for all available media types (JSON, YAML, CBOR and Kubernetes Protobuf).
930+
For Protobuf, the
931+
`Accept` header would be
932+
`application/vnd.kubernetes.protobuf;as=PartialObjectMetadata;g=meta.k8s.io;v=v1`.
933+
934+
The Kubernetes API server supports partial fetching for nearly all of its built-in APIs.
935+
However, you can use Kubernetes to access other API servers via the
936+
{{< glossary_tooltip text="aggregation layer" term_id="aggregation-layer" >}}, and those
937+
APIs may not support partial fetches.
938+
939+
If a client uses the `Accept` header to **only** request a response `...;as=PartialObjectMetadata;g=meta.k8s.io;v=v1`,
940+
and accesses an API that doesn't support partial responses, Kubernetes responds
941+
with a 406 HTTP error.
942+
943+
944+
If falling back to full objects in that case is desired, clients can add `,application/json`
945+
(or any other supported encoding) to their Accept header, and handle either
946+
PartialObjectMetadata or full objects in the response. It's a good idea to specify
947+
that a partial response is preferred, using the `q` (_quality_) parameter. For example:
948+
949+
```http
950+
Accept: application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1, application/json;q=0.9
951+
```
952+
953+
For more information on content type negotiation, see the
954+
[MDN Content Negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation).
955+
848956
## Resource deletion
849957

850958
When you **delete** a resource this takes place in two phases.

0 commit comments

Comments
 (0)