diff --git a/CHANGELOG.md b/CHANGELOG.md index a143794d1..15f51d3ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ UNRELEASED =================== * see https://github.com/clux/kube-rs/compare/0.51.0...master + * `kube`: BREAKING: ListParams bookmarks default enabled- #226 via + - renames `ListParams::allow_bookmarks` to `ListParams::bookmarks` + - `ListParams::default()` sets `bookmark` to true to avoid bad bad defaults + - `ListParams::allow_bookmarks` replaced by `ListParams::disable_bookmarks` 0.51.0 / 2021-02-28 =================== diff --git a/examples/configmap_watcher.rs b/examples/configmap_watcher.rs index ea72d1281..a3b3703e9 100644 --- a/examples/configmap_watcher.rs +++ b/examples/configmap_watcher.rs @@ -15,7 +15,7 @@ async fn main() -> anyhow::Result<()> { let namespace = std::env::var("NAMESPACE").unwrap_or("default".into()); let cms: Api = Api::namespaced(client, &namespace); - let lp = ListParams::default().allow_bookmarks(); + let lp = ListParams::default(); let mut w = watcher(cms, lp).boxed(); while let Some(event) = w.try_next().await? { diff --git a/kube/src/api/params.rs b/kube/src/api/params.rs index 7b8d834a8..8bfb7cf75 100644 --- a/kube/src/api/params.rs +++ b/kube/src/api/params.rs @@ -3,7 +3,7 @@ use crate::{Error, Result}; use serde::Serialize; /// Common query parameters used in watch/list/delete calls on collections -#[derive(Default, Clone)] +#[derive(Clone)] #[allow(missing_docs)] pub struct ListParams { /// A selector to restrict the list of returned objects by their labels. @@ -32,7 +32,7 @@ pub struct ListParams { /// If this is not a watch, this field is ignored. /// If the feature gate WatchBookmarks is not enabled in apiserver, /// this field is ignored. - pub allow_bookmarks: bool, + pub bookmarks: bool, /// Limit the number of results. /// @@ -47,6 +47,21 @@ pub struct ListParams { pub continue_token: Option, } +impl Default for ListParams { + fn default() -> Self { + Self { + // bookmarks stable since 1.17, and backwards compatible + bookmarks: true, + + label_selector: None, + field_selector: None, + timeout: None, + limit: None, + continue_token: None, + } + } +} + impl ListParams { pub(crate) fn validate(&self) -> Result<()> { if let Some(to) = &self.timeout { @@ -99,9 +114,12 @@ impl ListParams { self } - /// Enables watch bookmarks from the api server if supported - pub fn allow_bookmarks(mut self) -> Self { - self.allow_bookmarks = true; + /// Disables watch bookmarks to simplify watch handling + /// + /// This is not recommended to use with production watchers as it can cause desyncs. + /// See [#219](https://github.com/clux/kube-rs/issues/219) for details. + pub fn disable_bookmarks(mut self) -> Self { + self.bookmarks = false; self } diff --git a/kube/src/api/resource.rs b/kube/src/api/resource.rs index eac22de28..7fd165780 100644 --- a/kube/src/api/resource.rs +++ b/kube/src/api/resource.rs @@ -140,7 +140,7 @@ impl Resource { if let Some(labels) = &lp.label_selector { qp.append_pair("labelSelector", &labels); } - if lp.allow_bookmarks { + if lp.bookmarks { qp.append_pair("allowWatchBookmarks", "true"); } @@ -474,7 +474,7 @@ mod test { let req = r.watch(&gp, "0").unwrap(); assert_eq!( req.uri(), - "/api/v1/namespaces/ns/pods?&watch=true&resourceVersion=0&timeoutSeconds=290" + "/api/v1/namespaces/ns/pods?&watch=true&resourceVersion=0&timeoutSeconds=290&allowWatchBookmarks=true" ); } #[test]