Skip to content

Commit 797f0e6

Browse files
Tim Bannisterapelissedivya-mohan0209
committed
Improve docs relating to patching and SSA
Co-authored-by: Antoine Pelisse <[email protected]> Co-authored-by: Divya Mohan <[email protected]>
1 parent ea515e9 commit 797f0e6

File tree

2 files changed

+360
-184
lines changed

2 files changed

+360
-184
lines changed

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

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ For PUT requests, Kubernetes internally classifies these as either **create** or
7676
based on the state of the existing object. An **update** is different from a **patch**; the
7777
HTTP verb for a **patch** is PATCH.
7878

79+
7980
## Resource URIs
8081

8182
All resource types are either scoped by the cluster (`/apis/GROUP/VERSION/*`) or to a
@@ -162,7 +163,7 @@ For example:
162163
```
163164

164165
2. Starting from resource version 10245, receive notifications of any API operations
165-
(such as **create**, **delete**, **apply** or **update**) that affect Pods in the
166+
(such as **create**, **delete**, **patch** or **update**) that affect Pods in the
166167
_test_ namespace. Each change notification is a JSON document. The HTTP response body
167168
(served as `application/json`) consists a series of JSON documents.
168169

@@ -750,7 +751,7 @@ Once the last finalizer is removed, the resource is actually removed from etcd.
750751

751752
## Single resource API
752753

753-
The Kubernetes API verbs **get**, **create**, **apply**, **update**, **patch**,
754+
The Kubernetes API verbs **get**, **create**, **update**, **patch**,
754755
**delete** and **proxy** support single resources only.
755756
These verbs with single resource support have no support for submitting multiple
756757
resources together in an ordered or unordered list or transaction.
@@ -937,15 +938,70 @@ rules:
937938

938939
See [Authorization Overview](/docs/reference/access-authn-authz/authorization/).
939940

940-
## Server Side Apply
941+
## Updates to existing resources {#patch-and-apply}
942+
943+
You can overwrite (**update**) an existing resource - for example, a ConfigMap -
944+
using an HTTP PUT. For a PUT request, it is the client's responsibility to specify
945+
the `resourceVersion` (taking this from the object being updated). Kubernetes uses
946+
that `resourceVersion` information so that the API server can detect lost updates
947+
and reject requests made by a client that is out of date with the cluster.
948+
In the event that the resource has changed (the `resourceVersion` the client
949+
provided is stale), the API server returns a `409 Conflict` error response.
950+
951+
Instead of sending a PUT request, the client can send an instruction to the API
952+
server to **patch** an existing resource. A **patch** is typically appropriate
953+
if the change that the client wants to make isn't conditional on the existing data. Clients that need effective detection of lost updates should consider
954+
making their request conditional on the existing `resourceVersion` (either HTTP PUT or HTTP PATCH),
955+
and then handle any retries that are needed in case there is a conflict.
956+
957+
The Kubernetes API supports four different PATCH operations, determined by their
958+
corresponding HTTP `Content-Type` header:
959+
960+
`application/apply-patch+yaml`
961+
: Server Side Apply YAML (a Kubernetes-specific extension, based on YAML).
962+
All JSON documents are valid YAML, so you can also submit JSON using this
963+
media type. See [Server Side Apply serialization](/docs/reference/using-api/server-side-apply/#serialization)
964+
for more details.
965+
To Kubernetes, this is a **create** operation if the object does not exist,
966+
or a **patch** operation if the object already exists.
967+
968+
`application/json-patch+json`
969+
: JSON Patch, as defined in [RFC6902](https://tools.ietf.org/html/rfc6902).
970+
A JSON patch is a sequence of operations that are executed on the resource;
971+
for example `{"op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ]}`.
972+
To Kubernetes, this is a **patch** operation.
973+
974+
A **patch** using `application/json-patch+json` can include conditions to
975+
validate consistency, allowing the operation to fail if those conditions
976+
are not met (for example, to avoid a lost update).
977+
978+
`application/merge-patch+json`
979+
: JSON Merge Patch, as defined in [RFC7386](https://tools.ietf.org/html/rfc7386).
980+
A JSON Merge Patch is essentially a partial representation of the resource.
981+
The submitted JSON is combined with the current resource to create a new one,
982+
then the new one is saved.
983+
To Kubernetes, this is a **patch** operation.
984+
985+
`application/strategic-merge-patch+json`
986+
: Strategic Merge Patch (a Kubernetes-specific extension based on JSON).
987+
Strategic Merge Patch is a custom implementation of JSON Merge Patch.
988+
To Kubernetes, this is a **patch** operation.
989+
990+
{{< note >}}
991+
The Kubernetes _server side apply_ mechanism has superseded Strategic Merge
992+
Patch.
993+
{{< /note >}}
941994

942995
Kubernetes' [Server Side Apply](/docs/reference/using-api/server-side-apply/)
943996
feature allows the control plane to track managed fields for newly created objects.
944997
Server Side Apply provides a clear pattern for managing field conflicts,
945-
offers server-side `Apply` and `Update` operations, and replaces the
998+
offers server-side **apply** and **update** operations, and replaces the
946999
client-side functionality of `kubectl apply`.
9471000

948-
The API verb for Server-Side Apply is **apply**.
1001+
For Server-Side Apply, Kubernetes treats the request as a **create** if the object
1002+
does not yet exist, and a **patch** otherwise. For other requests that use PATCH
1003+
at the HTTP level, the logical Kubernetes operation is always **patch**.
1004+
9491005
See [Server Side Apply](/docs/reference/using-api/server-side-apply/) for more details.
9501006

9511007
## Resource versions

0 commit comments

Comments
 (0)