Skip to content

Commit

Permalink
clear clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Porto Carrero <[email protected]>
  • Loading branch information
casualjim committed Aug 13, 2023
1 parent ec87b95 commit 651b526
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
default-members = ["kube"]
resolver = "2"
members = [
"kube",
"kube-client",
Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/client/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub mod rustls_tls {

let mut client_config = if let Some((chain, pkey)) = identity_pem.map(client_auth).transpose()? {
config_builder
.with_single_cert(chain, pkey)
.with_client_auth_cert(chain, pkey)
.map_err(Error::InvalidPrivateKey)?
} else {
config_builder.with_no_client_auth()
Expand Down
13 changes: 4 additions & 9 deletions kube-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ pub struct WatchParams {
/// when request started being processed.
/// - `resourceVersionMatch` set to any other value or unset
/// Invalid error is returned.
///
/// Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward
/// compatibility reasons) and to false otherwise.
pub send_initial_events: bool,
}

Expand All @@ -341,12 +338,10 @@ impl WatchParams {
return Err(Error::Validation("WatchParams::timeout must be < 295s".into()));
}
}
if self.send_initial_events {
if !self.bookmarks {
return Err(Error::Validation(
"WatchParams::bookmarks must be set when using send_initial_events".into(),
));
}
if self.send_initial_events && !self.bookmarks {
return Err(Error::Validation(
"WatchParams::bookmarks must be set when using send_initial_events".into(),
));
}
Ok(())
}
Expand Down
26 changes: 18 additions & 8 deletions kube-runtime/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub enum ListSemantic {

/// Configurable watcher listwatch semantics
#[derive(Clone, Default, Debug, PartialEq)]
pub enum WatcherMode {
pub enum InitialListStrategy {
#[default]
ListWatch,
/// Kubernetes 1.27 Streaming Lists
Expand Down Expand Up @@ -232,6 +232,8 @@ pub struct Config {
/// Semantics for list calls.
///
/// Configures re-list for performance vs. consistency.
///
/// NB: This option only has an effect for [`WatcherMode::ListWatch`].
pub list_semantic: ListSemantic,

/// Kubernetes 1.27 Streaming Lists
Expand All @@ -247,14 +249,16 @@ pub struct Config {
///
/// See https://kubernetes.io/docs/reference/using-api/api-concepts/#streaming-lists
/// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#design-details
pub watcher_mode: WatcherMode,
pub initial_list_strategy: InitialListStrategy,

/// Maximum number of objects retrieved per list operation resyncs.
///
/// This can reduce the memory consumption during resyncs, at the cost of requiring more
/// API roundtrips to complete.
///
/// Defaults to 500. Note that `None` represents unbounded.
///
/// NB: This option only has an effect for [`WatcherMode::ListWatch`].
pub page_size: Option<u32>,

/// Enables watch events with type "BOOKMARK".
Expand All @@ -275,7 +279,7 @@ impl Default for Config {
// same default page size limit as client-go
// https://github.com/kubernetes/client-go/blob/aed71fa5cf054e1c196d67b2e21f66fd967b8ab1/tools/pager/pager.go#L31
page_size: Some(500),
watcher_mode: WatcherMode::ListWatch,
initial_list_strategy: InitialListStrategy::ListWatch,
}
}
}
Expand Down Expand Up @@ -322,13 +326,17 @@ impl Config {
}

/// Sets list semantic to configure re-list performance and consistency
///
/// NB: This option only has an effect for [`WatcherMode::ListWatch`].
#[must_use]
pub fn list_semantic(mut self, semantic: ListSemantic) -> Self {
self.list_semantic = semantic;
self
}

/// Sets list semantic to `Any` to improve list performance
///
/// NB: This option only has an effect for [`WatcherMode::ListWatch`].
#[must_use]
pub fn any_semantic(self) -> Self {
self.list_semantic(ListSemantic::Any)
Expand All @@ -348,6 +356,8 @@ impl Config {
///
/// This can reduce the memory consumption during resyncs, at the cost of requiring more
/// API roundtrips to complete.
///
/// NB: This option only has an effect for [`WatcherMode::ListWatch`].
#[must_use]
pub fn page_size(mut self, page_size: u32) -> Self {
self.page_size = Some(page_size);
Expand All @@ -358,7 +368,7 @@ impl Config {
/// Sets list semantic to `Stream` to make use of watch bookmarks
#[must_use]
pub fn streaming_lists(mut self) -> Self {
self.watcher_mode = WatcherMode::StreamingList;
self.initial_list_strategy = InitialListStrategy::StreamingList;
self
}

Expand Down Expand Up @@ -387,7 +397,7 @@ impl Config {
field_selector: self.field_selector.clone(),
timeout: self.timeout,
bookmarks: self.bookmarks,
send_initial_events: self.watcher_mode == WatcherMode::StreamingList,
send_initial_events: self.initial_list_strategy == InitialListStrategy::StreamingList,
}
}
}
Expand Down Expand Up @@ -456,8 +466,8 @@ where
State::Empty {
continue_token,
mut objects,
} => match wc.watcher_mode {
WatcherMode::ListWatch => {
} => match wc.initial_list_strategy {
InitialListStrategy::ListWatch => {
let mut lp = wc.to_list_params();
lp.continue_token = continue_token;
match api.list(&lp).await {
Expand Down Expand Up @@ -492,7 +502,7 @@ where
}
}
}
WatcherMode::StreamingList => match api.watch(&wc.to_watch_params(), "0").await {
InitialListStrategy::StreamingList => match api.watch(&wc.to_watch_params(), "0").await {
Ok(stream) => (None, State::IntialWatch { stream, objects }),
Err(err) => {
if std::matches!(err, ClientErr::Api(ErrorResponse { code: 403, .. })) {
Expand Down

0 comments on commit 651b526

Please sign in to comment.