Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update k8s-openapi #531

Merged
merged 10 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions examples/configmapgen_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ async fn reconcile(generator: ConfigMapGenerator, ctx: Context<Data>) -> 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::<ConfigMapGenerator>(generator.metadata.clone())?
}]),
}],
..ObjectMeta::default()
},
data: Some(contents),
data: contents,
..Default::default()
};
let cm_api = Api::<ConfigMap>::namespaced(
Expand Down
4 changes: 2 additions & 2 deletions examples/crd_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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) => {
Expand Down
10 changes: 4 additions & 6 deletions examples/crd_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ async fn wait_for_crd_ready(crds: &Api<CustomResourceDefinition>) -> 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(());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/crd_derive_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ async fn create_crd(client: Client) -> Result<CustomResourceDefinition> {
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);
Expand Down
1 change: 0 additions & 1 deletion examples/node_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async fn check_for_node_failures(events: &Api<Event>, 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
Expand Down
23 changes: 11 additions & 12 deletions examples/pod_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ async fn main() -> Result<()> {

fn pod_unready(p: &Pod) -> Option<String> {
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::<Vec<_>>()
.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::<Vec<_>>()
.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
}
13 changes: 6 additions & 7 deletions examples/secret_reflector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ enum Decoded {
fn decode(secret: &Secret) -> BTreeMap<String, Decoded> {
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
Expand Down
5 changes: 2 additions & 3 deletions kube-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion kube-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// ```
Expand Down
21 changes: 8 additions & 13 deletions kube-core/src/resource.rs
Original file line number Diff line number Diff line change
@@ -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;
olix0r marked this conversation as resolved.
Show resolved Hide resolved
use std::{borrow::Cow, collections::BTreeMap};

/// An accessor trait for a kubernetes Resource.
Expand Down Expand Up @@ -148,10 +147,6 @@ pub trait ResourceExt: Resource {
fn finalizers_mut(&mut self) -> &mut Vec<String>;
}

// TODO: replace with ordinary static when BTreeMap::new() is no longer
// const-unstable.
static EMPTY_MAP: Lazy<BTreeMap<String, String>> = Lazy::new(BTreeMap::new);

impl<K: Resource> ResourceExt for K {
fn name(&self) -> String {
self.meta().name.clone().expect(".metadata.name missing")
Expand All @@ -170,35 +165,35 @@ impl<K: Resource> ResourceExt for K {
}

fn labels(&self) -> &BTreeMap<String, String> {
self.meta().labels.as_ref().unwrap_or_else(|| &*EMPTY_MAP)
&self.meta().labels
}

fn labels_mut(&mut self) -> &mut BTreeMap<String, String> {
self.meta_mut().labels.get_or_insert_with(BTreeMap::new)
&mut self.meta_mut().labels
}

fn annotations(&self) -> &BTreeMap<String, String> {
self.meta().annotations.as_ref().unwrap_or_else(|| &*EMPTY_MAP)
&self.meta().annotations
}

fn annotations_mut(&mut self) -> &mut BTreeMap<String, String> {
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<OwnerReference> {
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<String> {
self.meta_mut().finalizers.get_or_insert_with(Vec::new)
&mut self.meta_mut().finalizers
}
}

Expand Down
2 changes: 1 addition & 1 deletion kube-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions kube-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
1 change: 0 additions & 1 deletion kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
})
}
Expand Down
4 changes: 2 additions & 2 deletions kube-runtime/src/reflector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions kube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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"]
2 changes: 1 addition & 1 deletion kube/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ mod tests {

let pods: Api<Pod> = 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();
}
}
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }