diff --git a/README.md b/README.md index bb72e4b49..00412109f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Select a version of `kube` along with the generated [k8s-openapi](https://github [dependencies] kube = "0.56.0" kube-runtime = "0.56.0" -k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] } +k8s-openapi = { version = "0.12.0", default-features = false, features = ["v1_20"] } ``` [Features are available](https://github.com/clux/kube-rs/blob/master/kube/Cargo.toml#L18). @@ -159,7 +159,7 @@ Kube has basic support ([with caveats](https://github.com/clux/kube-rs/issues?q= [dependencies] kube = { version = "0.56.0", default-features = false, features = ["client", "rustls-tls"] } kube-runtime = { version = "0.56.0" } -k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] } +k8s-openapi = { version = "0.12.0", default-features = false, features = ["v1_20"] } ``` This will pull in `rustls` and `hyper-rustls`. diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f45272333..10622bf17 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -31,7 +31,7 @@ kube = { path = "../kube", version = "^0.56.0", default-features = false, featur kube-derive = { path = "../kube-derive", version = "^0.56.0", default-features = false } # only needed to opt out of schema kube-runtime = { path = "../kube-runtime", version = "^0.56.0"} kube-core = { path = "../kube-core", version = "^0.56.0", default-features = false } -k8s-openapi = { version = "0.11.0", features = ["v1_20"], default-features = false } +k8s-openapi = { version = "0.12.0", features = ["v1_20"], default-features = false } log = "0.4.11" serde = { version = "1.0.118", features = ["derive"] } serde_json = "1.0.61" diff --git a/examples/configmapgen_controller.rs b/examples/configmapgen_controller.rs index c70e9ee49..48f3e7e3a 100644 --- a/examples/configmapgen_controller.rs +++ b/examples/configmapgen_controller.rs @@ -61,13 +61,13 @@ async fn reconcile(generator: ConfigMapGenerator, ctx: Context) -> Result< let cm = ConfigMap { metadata: ObjectMeta { name: generator.metadata.name.clone(), - owner_references: Some(vec![OwnerReference { + owner_references: vec![OwnerReference { controller: Some(true), ..object_to_owner_reference::(generator.metadata.clone())? - }]), + }], ..ObjectMeta::default() }, - data: Some(contents), + data: contents, ..Default::default() }; let cm_api = Api::::namespaced( diff --git a/examples/crd_api.rs b/examples/crd_api.rs index b22ea4803..2fd93ce2d 100644 --- a/examples/crd_api.rs +++ b/examples/crd_api.rs @@ -52,7 +52,7 @@ async fn main() -> anyhow::Result<()> { info!( "Deleting {}: ({:?})", o.name(), - o.status.unwrap().conditions.unwrap().last() + o.status.unwrap().conditions.last() ); }) .map_right(|s| { @@ -213,7 +213,7 @@ async fn main() -> anyhow::Result<()> { info!( "Deleting {} CRD definition: {:?}", o.name(), - o.status.unwrap().conditions.unwrap().last() + o.status.unwrap().conditions.last() ); } Right(status) => { diff --git a/examples/crd_apply.rs b/examples/crd_apply.rs index f76c0ca59..0b0f66a56 100644 --- a/examples/crd_apply.rs +++ b/examples/crd_apply.rs @@ -92,12 +92,10 @@ async fn wait_for_crd_ready(crds: &Api) -> anyhow::Res if let WatchEvent::Modified(s) = status { info!("Modify event for {}", s.name()); if let Some(s) = s.status { - if let Some(conds) = s.conditions { - if let Some(pcond) = conds.iter().find(|c| c.type_ == "NamesAccepted") { - if pcond.status == "True" { - info!("crd was accepted: {:?}", pcond); - return Ok(()); - } + if let Some(pcond) = s.conditions.iter().find(|c| c.type_ == "NamesAccepted") { + if pcond.status == "True" { + info!("crd was accepted: {:?}", pcond); + return Ok(()); } } } diff --git a/examples/crd_derive_schema.rs b/examples/crd_derive_schema.rs index 1dc328f75..4088c382d 100644 --- a/examples/crd_derive_schema.rs +++ b/examples/crd_derive_schema.rs @@ -235,9 +235,9 @@ async fn create_crd(client: Client) -> Result { let accepted = crd .status .as_ref() - .and_then(|s| s.conditions.as_ref()) - .map(|cs| { - cs.iter() + .map(|s| { + s.conditions + .iter() .any(|c| c.type_ == "NamesAccepted" && c.status == "True") }) .unwrap_or(false); diff --git a/examples/node_watcher.rs b/examples/node_watcher.rs index f3a5fabad..6bb22a8cc 100644 --- a/examples/node_watcher.rs +++ b/examples/node_watcher.rs @@ -33,7 +33,6 @@ async fn check_for_node_failures(events: &Api, o: Node) -> anyhow::Result .status .unwrap() .conditions - .unwrap() .into_iter() .filter(|c| { // In a failed state either some of the extra conditions are not False diff --git a/examples/pod_watcher.rs b/examples/pod_watcher.rs index c8c011a41..320f79b11 100644 --- a/examples/pod_watcher.rs +++ b/examples/pod_watcher.rs @@ -29,19 +29,18 @@ async fn main() -> Result<()> { fn pod_unready(p: &Pod) -> Option { let status = p.status.as_ref().unwrap(); - if let Some(conds) = &status.conditions { - let failed = conds - .into_iter() - .filter(|c| c.type_ == "Ready" && c.status == "False") - .map(|c| c.message.clone().unwrap_or_default()) - .collect::>() - .join(","); - if !failed.is_empty() { - if p.metadata.labels.as_ref().unwrap().contains_key("job-name") { - return None; // ignore job based pods, they are meant to exit 0 - } - return Some(format!("Unready pod {}: {}", p.name(), failed)); + let failed = status + .conditions + .iter() + .filter(|c| c.type_ == "Ready" && c.status == "False") + .map(|c| c.message.clone().unwrap_or_default()) + .collect::>() + .join(","); + if !failed.is_empty() { + if p.metadata.labels.contains_key("job-name") { + return None; // ignore job based pods, they are meant to exit 0 } + return Some(format!("Unready pod {}: {}", p.name(), failed)); } None } diff --git a/examples/secret_reflector.rs b/examples/secret_reflector.rs index bbedff9a4..068099472 100644 --- a/examples/secret_reflector.rs +++ b/examples/secret_reflector.rs @@ -20,13 +20,12 @@ enum Decoded { fn decode(secret: &Secret) -> BTreeMap { let mut res = BTreeMap::new(); // Ignoring binary data for now - if let Some(data) = secret.data.clone() { - for (k, v) in data { - if let Ok(b) = std::str::from_utf8(&v.0) { - res.insert(k, Decoded::Utf8(b.to_string())); - } else { - res.insert(k, Decoded::Bytes(v.0)); - } + let data = secret.data.clone(); + for (k, v) in data { + if let Ok(b) = std::str::from_utf8(&v.0) { + res.insert(k, Decoded::Utf8(b.to_string())); + } else { + res.insert(k, Decoded::Bytes(v.0)); } } res diff --git a/kube-core/Cargo.toml b/kube-core/Cargo.toml index 991bbdbe3..9125b0b8a 100644 --- a/kube-core/Cargo.toml +++ b/kube-core/Cargo.toml @@ -20,18 +20,17 @@ jsonpatch = ["json-patch"] serde = { version = "1.0.118", features = ["derive"] } serde_json = "1.0.61" thiserror = "1.0.23" -once_cell = "1.7.2" form_urlencoded = "1.0.1" http = "0.2.2" json-patch = { version = "0.2.6", optional = true } [dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false features = [] [dev-dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false features = ["v1_20"] diff --git a/kube-core/src/params.rs b/kube-core/src/params.rs index 191bde16b..b3c9b596a 100644 --- a/kube-core/src/params.rs +++ b/kube-core/src/params.rs @@ -192,7 +192,7 @@ impl PostParams { /// use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta; /// let r = Role { /// metadata: ObjectMeta { name: Some("user".into()), ..ObjectMeta::default() }, -/// rules: Some(vec![]) +/// rules: vec![] /// }; /// let patch = Patch::Apply(&r); /// ``` diff --git a/kube-core/src/resource.rs b/kube-core/src/resource.rs index 77c7a53c1..a60777aae 100644 --- a/kube-core/src/resource.rs +++ b/kube-core/src/resource.rs @@ -1,6 +1,5 @@ pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta; use k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference; -use once_cell::sync::Lazy; use std::{borrow::Cow, collections::BTreeMap}; /// An accessor trait for a kubernetes Resource. @@ -148,10 +147,6 @@ pub trait ResourceExt: Resource { fn finalizers_mut(&mut self) -> &mut Vec; } -// TODO: replace with ordinary static when BTreeMap::new() is no longer -// const-unstable. -static EMPTY_MAP: Lazy> = Lazy::new(BTreeMap::new); - impl ResourceExt for K { fn name(&self) -> String { self.meta().name.clone().expect(".metadata.name missing") @@ -170,35 +165,35 @@ impl ResourceExt for K { } fn labels(&self) -> &BTreeMap { - self.meta().labels.as_ref().unwrap_or_else(|| &*EMPTY_MAP) + &self.meta().labels } fn labels_mut(&mut self) -> &mut BTreeMap { - self.meta_mut().labels.get_or_insert_with(BTreeMap::new) + &mut self.meta_mut().labels } fn annotations(&self) -> &BTreeMap { - self.meta().annotations.as_ref().unwrap_or_else(|| &*EMPTY_MAP) + &self.meta().annotations } fn annotations_mut(&mut self) -> &mut BTreeMap { - self.meta_mut().annotations.get_or_insert_with(BTreeMap::new) + &mut self.meta_mut().annotations } fn owner_references(&self) -> &[OwnerReference] { - self.meta().owner_references.as_deref().unwrap_or_default() + self.meta().owner_references.as_slice() } fn owner_references_mut(&mut self) -> &mut Vec { - self.meta_mut().owner_references.get_or_insert_with(Vec::new) + &mut self.meta_mut().owner_references } fn finalizers(&self) -> &[String] { - self.meta().finalizers.as_deref().unwrap_or_default() + self.meta().finalizers.as_slice() } fn finalizers_mut(&mut self) -> &mut Vec { - self.meta_mut().finalizers.get_or_insert_with(Vec::new) + &mut self.meta_mut().finalizers } } diff --git a/kube-derive/Cargo.toml b/kube-derive/Cargo.toml index ffd1cd107..2d411f745 100644 --- a/kube-derive/Cargo.toml +++ b/kube-derive/Cargo.toml @@ -29,7 +29,7 @@ schema = [] serde = { version = "1.0.118", features = ["derive"] } serde_yaml = "0.8.17" kube = { path = "../kube", default-features = false } -k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] } +k8s-openapi = { version = "0.12.0", default-features = false, features = ["v1_20"] } schemars = { version = "0.8.0", features = ["chrono"] } chrono = "0.4.19" trybuild = "1.0" diff --git a/kube-runtime/Cargo.toml b/kube-runtime/Cargo.toml index 4a646ca32..9e65172a5 100644 --- a/kube-runtime/Cargo.toml +++ b/kube-runtime/Cargo.toml @@ -25,7 +25,7 @@ dashmap = "4.0.1" tokio-util = { version = "0.6.0", features = ["time"] } [dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false [dev-dependencies] @@ -37,6 +37,6 @@ rand = "0.8.0" schemars = "0.8.0" [dev-dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false features = ["v1_20"] diff --git a/kube-runtime/src/controller/mod.rs b/kube-runtime/src/controller/mod.rs index 2b5c150af..50521115a 100644 --- a/kube-runtime/src/controller/mod.rs +++ b/kube-runtime/src/controller/mod.rs @@ -104,7 +104,6 @@ where let dt = owner_type.clone(); meta.owner_references .into_iter() - .flatten() .flat_map(move |owner| ObjectRef::from_owner_ref(ns.as_deref(), &owner, dt.clone())) }) } diff --git a/kube-runtime/src/reflector/mod.rs b/kube-runtime/src/reflector/mod.rs index 12bf7497c..6051cbaa7 100644 --- a/kube-runtime/src/reflector/mod.rs +++ b/kube-runtime/src/reflector/mod.rs @@ -70,11 +70,11 @@ mod tests { ..ConfigMap::default() }; let updated_cm = ConfigMap { - data: Some({ + data: { let mut data = BTreeMap::new(); data.insert("data".to_string(), "present!".to_string()); data - }), + }, ..cm.clone() }; reflector( diff --git a/kube/Cargo.toml b/kube/Cargo.toml index e94a6d1a0..a3668bc34 100644 --- a/kube/Cargo.toml +++ b/kube/Cargo.toml @@ -73,7 +73,7 @@ rand = { version = "0.8.3", optional = true } tracing = { version = "0.1.25", features = ["log"], optional = true } [dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false features = [] @@ -85,6 +85,6 @@ tokio-test = "0.4.0" tower-test = "0.4.0" [dev-dependencies.k8s-openapi] -version = "0.11.0" +version = "0.12.0" default-features = false features = ["v1_20"] diff --git a/kube/src/client/mod.rs b/kube/src/client/mod.rs index 2fe65370e..f655529b4 100644 --- a/kube/src/client/mod.rs +++ b/kube/src/client/mod.rs @@ -606,7 +606,7 @@ mod tests { let pods: Api = Api::default_namespaced(Client::new(mock_service, "default")); let pod = pods.get("test").await.unwrap(); - assert_eq!(pod.metadata.annotations.unwrap().get("kube-rs").unwrap(), "test"); + assert_eq!(pod.metadata.annotations.get("kube-rs").unwrap(), "test"); spawned.await.unwrap(); } } diff --git a/tests/Cargo.toml b/tests/Cargo.toml index a9723ee45..dde2235e4 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -17,7 +17,7 @@ anyhow = "1.0.37" env_logger = "0.8.2" futures = "0.3.8" kube = { path = "../kube", version = "^0.56.0"} -k8s-openapi = { version = "0.11.0", features = ["v1_20"], default-features = false } +k8s-openapi = { version = "0.12.0", features = ["v1_20"], default-features = false } log = "0.4.11" serde_json = "1.0.61" tokio = { version = "1.0.1", features = ["full"] }