Skip to content

[Merged by Bors] - Update to kube-rs 0.82.2 and dependencies #589

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

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
29 changes: 16 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Pod>(&client.default_namespace, lp.clone()),
/// client.wait_created::<Pod>(&client.default_namespace, watcher_config),
/// )
/// .await;
/// }
/// ```
///
pub async fn wait_created<T>(&self, namespace: &T::Namespace, lp: ListParams)
pub async fn wait_created<T>(&self, namespace: &T::Namespace, watcher_config: watcher::Config)
where
T: Resource + GetApi + Clone + Debug + DeserializeOwned + Send + 'static,
<T as Resource>::DynamicType: Default,
{
let api: Api<T> = 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()))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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::<Pod>(&client.default_namespace, lp.clone()),
client.wait_created::<Pod>(&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::<Pod>(api, lp).boxed();
let mut ready_watcher = kube::runtime::watcher::<Pod>(api, watcher_config).boxed();
while let Some(result) = ready_watcher.next().await {
match result {
Ok(event) => match event {
Expand Down Expand Up @@ -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::<Pod>(&client.default_namespace, lp.clone()),
client.wait_created::<Pod>(&client.default_namespace, watcher_config),
)
.await;

Expand Down
9 changes: 2 additions & 7 deletions src/commons/product_image_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,16 @@ pub struct ResolvedProductImage {
pub pull_secrets: Option<Vec<LocalObjectReference>>,
}

#[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();
Expand Down
11 changes: 4 additions & 7 deletions src/commons/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
Path,
/// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access>
#[default]
VirtualHosted,
}

impl Default for S3AccessStyle {
fn default() -> Self {
S3AccessStyle::VirtualHosted
}
}

#[cfg(test)]
mod test {
use std::str;
Expand Down