Skip to content

Commit a6060c4

Browse files
aviramhaclux
andauthored
update jsonptr + json-patch (kube-rs#1600)
Pointer -> PointerBuf Signed-off-by: Aviram Hassan <[email protected]> Co-authored-by: Eirik A <[email protected]>
1 parent 2280962 commit a6060c4

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ hyper-openssl = "0.10.2"
5757
hyper-rustls = { version = "0.27.1", default-features = false }
5858
hyper-socks2 = { version = "0.9.0", default-features = false }
5959
hyper-timeout = "0.5.1"
60-
json-patch = "2.0.0"
61-
jsonptr = "0.4.7"
60+
json-patch = "3"
61+
jsonptr = "0.6"
6262
jsonpath-rust = "0.5.0"
6363
k8s-openapi = { version = "0.23.0", default-features = false }
6464
openssl = "0.10.36"

examples/admission_controller.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use jsonptr::Pointer;
1+
use jsonptr::PointerBuf;
22
use kube::core::{
33
admission::{AdmissionRequest, AdmissionResponse, AdmissionReview},
44
DynamicObject, Resource, ResourceExt,
@@ -76,13 +76,13 @@ fn mutate(res: AdmissionResponse, obj: &DynamicObject) -> Result<AdmissionRespon
7676
// Ensure labels exist before adding a key to it
7777
if obj.meta().labels.is_none() {
7878
patches.push(json_patch::PatchOperation::Add(json_patch::AddOperation {
79-
path: Pointer::new(["metadata", "labels"]),
79+
path: PointerBuf::from_tokens(["metadata", "labels"]),
8080
value: serde_json::json!({}),
8181
}));
8282
}
8383
// Add our label
8484
patches.push(json_patch::PatchOperation::Add(json_patch::AddOperation {
85-
path: Pointer::new(["metadata", "labels", "admission"]),
85+
path: PointerBuf::from_tokens(["metadata", "labels", "admission"]),
8686
value: serde_json::Value::String("modified-by-admission-controller".into()),
8787
}));
8888
Ok(res.with_patch(json_patch::Patch(patches))?)

kube-core/src/admission.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ pub enum Operation {
223223
/// .into_review();
224224
///
225225
/// use json_patch::{AddOperation, Patch, PatchOperation};
226-
/// use jsonptr::Pointer;
226+
/// use jsonptr::PointerBuf;
227227
///
228228
/// // A response adding a label to the resource.
229229
/// let _: AdmissionReview<_> = AdmissionResponse::from(&req)
230230
/// .with_patch(Patch(vec![PatchOperation::Add(AddOperation {
231-
/// path: Pointer::new(["metadata","labels","my-label"]),
231+
/// path: PointerBuf::from_tokens(["metadata","labels","my-label"]),
232232
/// value: serde_json::Value::String("my-value".to_owned()),
233233
/// })]))
234234
/// .unwrap()

kube-runtime/src/finalizer.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::controller::Action;
33
use futures::{TryFuture, TryFutureExt};
44
use json_patch::{AddOperation, PatchOperation, RemoveOperation, TestOperation};
5-
use jsonptr::Pointer;
5+
use jsonptr::PointerBuf;
66
use kube_client::{
77
api::{Patch, PatchParams},
88
Api, Resource, ResourceExt,
@@ -142,12 +142,12 @@ where
142142
// `Test` ensures that we fail instead of deleting someone else's finalizer
143143
// (in which case a new `Cleanup` event will be sent)
144144
PatchOperation::Test(TestOperation {
145-
path: Pointer::from_str(finalizer_path.as_str())
145+
path: PointerBuf::from_str(finalizer_path.as_str())
146146
.map_err(|_err| Error::InvalidFinalizer)?,
147147
value: finalizer_name.into(),
148148
}),
149149
PatchOperation::Remove(RemoveOperation {
150-
path: Pointer::from_str(finalizer_path.as_str())
150+
path: PointerBuf::from_str(finalizer_path.as_str())
151151
.map_err(|_err| Error::InvalidFinalizer)?,
152152
}),
153153
])),
@@ -164,12 +164,12 @@ where
164164
let patch = json_patch::Patch(if obj.finalizers().is_empty() {
165165
vec![
166166
PatchOperation::Test(TestOperation {
167-
path: Pointer::from_str("/metadata/finalizers")
167+
path: PointerBuf::from_str("/metadata/finalizers")
168168
.map_err(|_err| Error::InvalidFinalizer)?,
169169
value: serde_json::Value::Null,
170170
}),
171171
PatchOperation::Add(AddOperation {
172-
path: Pointer::from_str("/metadata/finalizers")
172+
path: PointerBuf::from_str("/metadata/finalizers")
173173
.map_err(|_err| Error::InvalidFinalizer)?,
174174
value: vec![finalizer_name].into(),
175175
}),
@@ -180,12 +180,12 @@ where
180180
// https://github.com/kube-rs/kube/issues/964#issuecomment-1197311254),
181181
// so we need to fail and retry if anyone else has added the finalizer in the meantime
182182
PatchOperation::Test(TestOperation {
183-
path: Pointer::from_str("/metadata/finalizers")
183+
path: PointerBuf::from_str("/metadata/finalizers")
184184
.map_err(|_err| Error::InvalidFinalizer)?,
185185
value: obj.finalizers().into(),
186186
}),
187187
PatchOperation::Add(AddOperation {
188-
path: Pointer::from_str("/metadata/finalizers/-")
188+
path: PointerBuf::from_str("/metadata/finalizers/-")
189189
.map_err(|_err| Error::InvalidFinalizer)?,
190190
value: finalizer_name.into(),
191191
}),

0 commit comments

Comments
 (0)