Skip to content

Commit aee3d38

Browse files
committed
update patch documentation - closes #142
1 parent a2d33fb commit aee3d38

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fmt:
1212
cargo +nightly fmt
1313

1414
doc:
15-
cargo +nightly doc --lib
15+
cargo +nightly doc --lib --features=derive,ws,oauth,jsonpatch
1616
xdg-open target/doc/kube/index.html
1717

1818
test:

kube/src/api/params.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,41 @@ impl PostParams {
144144

145145
/// Describes changes that should be applied to a resource
146146
///
147-
/// For all strategies except `Json`, patch can be represented with arbitrary
148-
/// serializable value, such as `serde_json::Value`. You may also want to use
149-
/// a `k8s-openapi` definition for the resource for the better type safety.
147+
/// Takes arbitrary serializable data for all strategies except `Json`.
148+
///
149+
/// We recommend using ([server-side](https://kubernetes.io/blog/2020/04/01/kubernetes-1.18-feature-server-side-apply-beta-2)) `Apply` patches on new kubernetes releases.
150+
///
151+
/// See [kubernetes patch docs](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment) for the older patch types.
152+
///
153+
/// Note that patches have different effects on different fields depending on their [merge-strategies](https://kubernetes.io/docs/reference/using-api/server-side-apply/#merge-strategy).
154+
/// These strategies are configurable when deriving your [`CustomResource`](kube_derive::CustomResource).
155+
///
156+
/// # Creating a patch via serde_json
157+
/// ```
158+
/// use kube::api::Patch;
159+
/// let patch = serde_json::json!({
160+
/// "apiVersion": "v1",
161+
/// "kind": "Pod",
162+
/// "metadata": {
163+
/// "name": "blog"
164+
/// },
165+
/// "spec": {
166+
/// "activeDeadlineSeconds": 5
167+
/// }
168+
/// });
169+
/// let patch = Patch::Apply(&patch);
170+
/// ```
171+
/// # Creating a patch from a type
172+
/// ```
173+
/// use kube::api::Patch;
174+
/// use k8s_openapi::api::rbac::v1::Role;
175+
/// use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
176+
/// let r = Role {
177+
/// metadata: ObjectMeta { name: Some("user".into()), ..ObjectMeta::default() },
178+
/// rules: Some(vec![])
179+
/// };
180+
/// let patch = Patch::Apply(&r);
181+
/// ```
150182
#[non_exhaustive]
151183
pub enum Patch<T: Serialize> {
152184
/// [Server side apply](https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply)

kube/src/api/typed.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,9 @@ where
193193
self.client.request_status::<ObjectList<K>>(req).await
194194
}
195195

196-
/// Patch a resource a subset of its properties
196+
/// Patch a subset of a resource's properties
197197
///
198-
/// Note that actual `patch` value depends on what `PatchStrategy` is used.
199-
/// It is configured in `PatchParams` and defauls to strategic merge
200-
/// patch.
201-
///
202-
/// See [kubernetes json patch types](https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment)
203-
/// for more information about their distinction.
198+
/// Takes a [`Patch`] along with [`PatchParams`] for the call.
204199
///
205200
/// ```no_run
206201
/// use kube::{api::{Api, PatchParams, Patch, Meta}, Client};
@@ -225,10 +220,8 @@ where
225220
/// Ok(())
226221
/// }
227222
/// ```
228-
/// [`Merge`]: super::PatchStrategy::Merge
229-
/// [`JSON`]: super::PatchStrategy::JSON
230-
/// [`Strategic`]: super::PatchStrategy::Strategic
231-
/// [`Apply`]: super::PatchStrategy::Apply
223+
/// [`Patch`]: super::Patch
224+
/// [`PatchParams`]: super::PatchParams
232225
pub async fn patch<P: Serialize>(&self, name: &str, pp: &PatchParams, patch: &Patch<P>) -> Result<K> {
233226
let req = self.resource.patch(name, &pp, patch)?;
234227
self.client.request::<K>(req).await

0 commit comments

Comments
 (0)