diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b5125e9..c8560f7ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Changed + +- kube: 0.78.0 -> 0.82.2 ([#589]). +- k8s-openapi: 0.17.0 -> 0.18.0 ([#589]). + +[#589]: https://github.com/stackabletech/operator-rs/pull/589 + ## [0.40.2] - 2023-04-12 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index a44a6d781..793e25e91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ clap = { version = "4.1.4", features = ["derive", "cargo", "env"] } const_format = "0.2.30" either = "1.8.1" futures = "0.3.26" -json-patch = "0.3.0" -k8s-openapi = { version = "0.17.0", default-features = false, features = ["schemars", "v1_26"] } -kube = { version = "0.78.0", features = ["jsonpatch", "runtime", "derive"] } +json-patch = "1.0.0" +k8s-openapi = { version = "0.18.0", default-features = false, features = ["schemars", "v1_26"] } +kube = { version = "0.82.2", features = ["jsonpatch", "runtime", "derive"] } lazy_static = "1.4.0" product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.4.0" } rand = "0.8.5" @@ -37,7 +37,7 @@ stackable-operator-derive = { path = "stackable-operator-derive" } snafu = "0.7.4" [dev-dependencies] -rstest = "0.16.0" +rstest = "0.17.0" tempfile = "3.3.0" [workspace] diff --git a/src/client.rs b/src/client.rs index 0436752fd..bff7c17b7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -9,7 +9,7 @@ use kube::api::{DeleteParams, ListParams, Patch, PatchParams, PostParams, Resour use kube::client::Client as KubeClient; use kube::core::Status; use kube::runtime::wait::delete::delete_and_finalize; -use kube::runtime::WatchStreamExt; +use kube::runtime::{watcher, WatchStreamExt}; use kube::{Api, Config}; use serde::de::DeserializeOwned; use serde::Serialize; @@ -426,34 +426,35 @@ impl Client { /// # Example /// /// ```no_run - /// use kube::api::ListParams; /// use std::time::Duration; /// use tokio::time::error::Elapsed; + /// use kube::runtime::watcher; /// use k8s_openapi::api::core::v1::Pod; /// use stackable_operator::client::{Client, create_client}; /// /// #[tokio::main] /// async fn main(){ + /// /// let client: Client = create_client(None).await.expect("Unable to construct client."); - /// let lp: ListParams = - /// ListParams::default().fields(&format!("metadata.name=nonexistent-pod")); + /// let watcher_config: watcher::Config = + /// watcher::Config::default().fields(&format!("metadata.name=nonexistent-pod")); /// /// // Will time out in 1 second unless the nonexistent-pod actually exists /// let wait_created_result: Result<(), Elapsed> = tokio::time::timeout( /// Duration::from_secs(1), - /// client.wait_created::(&client.default_namespace, lp.clone()), + /// client.wait_created::(&client.default_namespace, watcher_config), /// ) /// .await; /// } /// ``` /// - pub async fn wait_created(&self, namespace: &T::Namespace, lp: ListParams) + pub async fn wait_created(&self, namespace: &T::Namespace, watcher_config: watcher::Config) where T: Resource + GetApi + Clone + Debug + DeserializeOwned + Send + 'static, ::DynamicType: Default, { let api: Api = self.get_api(namespace); - let watcher = kube::runtime::watcher(api, lp).boxed(); + let watcher = kube::runtime::watcher(api, watcher_config).boxed(); watcher .applied_objects() .skip_while(|res| std::future::ready(res.is_err())) @@ -558,7 +559,8 @@ mod tests { use futures::StreamExt; use k8s_openapi::api::core::v1::{Container, Pod, PodSpec}; use k8s_openapi::apimachinery::pkg::apis::meta::v1::LabelSelector; - use kube::api::{ListParams, ObjectMeta, PostParams, ResourceExt}; + use kube::api::{ObjectMeta, PostParams, ResourceExt}; + use kube::runtime::watcher; use kube::runtime::watcher::Event; use std::collections::BTreeMap; use std::time::Duration; @@ -595,7 +597,7 @@ mod tests { .create(&PostParams::default(), &pod_to_wait_for) .await .expect("Test pod not created."); - let lp: ListParams = ListParams::default().fields(&format!( + let watcher_config: watcher::Config = watcher::Config::default().fields(&format!( "metadata.name={}", created_pod .metadata @@ -607,14 +609,14 @@ mod tests { // Timeout is not acceptable tokio::time::timeout( Duration::from_secs(30), // Busybox is ~5MB and sub 1 sec to start. - client.wait_created::(&client.default_namespace, lp.clone()), + client.wait_created::(&client.default_namespace, watcher_config.clone()), ) .await .expect("The tested wait_created function timed out."); // A second, manually constructed watcher is used to verify the ListParams filter out the correct resource // and the `wait_created` function returned when the correct resources had been detected. - let mut ready_watcher = kube::runtime::watcher::(api, lp).boxed(); + let mut ready_watcher = kube::runtime::watcher::(api, watcher_config).boxed(); while let Some(result) = ready_watcher.next().await { match result { Ok(event) => match event { @@ -649,12 +651,13 @@ mod tests { .await .expect("KUBECONFIG variable must be configured."); - let lp: ListParams = ListParams::default().fields("metadata.name=nonexistent-pod"); + let watcher_config: watcher::Config = + watcher::Config::default().fields("metadata.name=nonexistent-pod"); // There is no such pod, therefore the `wait_created` function call times out. let wait_created_result: Result<(), Elapsed> = tokio::time::timeout( Duration::from_secs(1), - client.wait_created::(&client.default_namespace, lp.clone()), + client.wait_created::(&client.default_namespace, watcher_config), ) .await; diff --git a/src/commons/product_image_selection.rs b/src/commons/product_image_selection.rs index 13a8e5796..7801f147a 100644 --- a/src/commons/product_image_selection.rs +++ b/src/commons/product_image_selection.rs @@ -67,21 +67,16 @@ pub struct ResolvedProductImage { pub pull_secrets: Option>, } -#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] #[serde(rename = "PascalCase")] #[derive(AsRefStr)] pub enum PullPolicy { + #[default] IfNotPresent, Always, Never, } -impl Default for PullPolicy { - fn default() -> PullPolicy { - PullPolicy::IfNotPresent - } -} - impl ProductImage { pub fn resolve(&self, image_base_name: &str) -> ResolvedProductImage { let image_pull_policy = self.pull_policy.as_ref().to_string(); diff --git a/src/commons/s3.rs b/src/commons/s3.rs index faba7a390..0d85f4e81 100644 --- a/src/commons/s3.rs +++ b/src/commons/s3.rs @@ -205,21 +205,18 @@ impl S3ConnectionSpec { } } -#[derive(strum::Display, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] +#[derive( + strum::Display, Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize, +)] #[strum(serialize_all = "PascalCase")] pub enum S3AccessStyle { /// Use path-style access as described in Path, /// Use as virtual hosted-style access as described in + #[default] VirtualHosted, } -impl Default for S3AccessStyle { - fn default() -> Self { - S3AccessStyle::VirtualHosted - } -} - #[cfg(test)] mod test { use std::str;