From 1d73dd1f641dc4748398bc0ab413d815d2ae3cf4 Mon Sep 17 00:00:00 2001 From: goenning Date: Thu, 17 Aug 2023 12:31:03 +0100 Subject: [PATCH 1/2] fix paging parameters when using any semantic Signed-off-by: goenning --- kube-core/src/params.rs | 28 ++++++++++++++++------------ kube-core/src/request.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/kube-core/src/params.rs b/kube-core/src/params.rs index 93d333f19..583befcb3 100644 --- a/kube-core/src/params.rs +++ b/kube-core/src/params.rs @@ -103,18 +103,22 @@ impl ListParams { } if let Some(continue_token) = &self.continue_token { qp.append_pair("continue", continue_token); - } - - if let Some(rv) = &self.resource_version { - qp.append_pair("resourceVersion", rv.as_str()); - } - match &self.version_match { - None => {} - Some(VersionMatch::NotOlderThan) => { - qp.append_pair("resourceVersionMatch", "NotOlderThan"); - } - Some(VersionMatch::Exact) => { - qp.append_pair("resourceVersionMatch", "Exact"); + } else { + // When there's a continue token, we don't want to set resourceVersion + if let Some(rv) = &self.resource_version { + if rv != "0" || (rv == "0" && self.limit.is_none()) { + qp.append_pair("resourceVersion", rv.as_str()); + + match &self.version_match { + None => {} + Some(VersionMatch::NotOlderThan) => { + qp.append_pair("resourceVersionMatch", "NotOlderThan"); + } + Some(VersionMatch::Exact) => { + qp.append_pair("resourceVersionMatch", "Exact"); + } + } + } } } } diff --git a/kube-core/src/request.rs b/kube-core/src/request.rs index 2490c925e..21805f72d 100644 --- a/kube-core/src/request.rs +++ b/kube-core/src/request.rs @@ -734,15 +734,35 @@ mod test { } #[test] - fn list_not_older() { + fn list_paged_any_semantic() { let url = corev1::Pod::url_path(&(), Some("ns")); - let gp = ListParams::default() - .at("20") - .matching(VersionMatch::NotOlderThan); + let gp = ListParams::default().limit(50).match_any(); let req = Request::new(url).list(&gp).unwrap(); assert_eq!( req.uri().query().unwrap(), - "&resourceVersion=20&resourceVersionMatch=NotOlderThan" + "&limit=50" + ); + } + + #[test] + fn list_paged_with_continue_any_semantic() { + let url = corev1::Pod::url_path(&(), Some("ns")); + let gp = ListParams::default().limit(50).continue_token("1234").match_any(); + let req = Request::new(url).list(&gp).unwrap(); + assert_eq!( + req.uri().query().unwrap(), + "&limit=50&continue=1234" + ); + } + + #[test] + fn list_paged_with_continue_starting_at() { + let url = corev1::Pod::url_path(&(), Some("ns")); + let gp = ListParams::default().limit(50).continue_token("1234").at("9999").matching(VersionMatch::Exact); + let req = Request::new(url).list(&gp).unwrap(); + assert_eq!( + req.uri().query().unwrap(), + "&limit=50&continue=1234" ); } From 086ef33182478f412a4138e503e7aa1438beee02 Mon Sep 17 00:00:00 2001 From: goenning Date: Sun, 20 Aug 2023 12:28:01 +0100 Subject: [PATCH 2/2] fmt Signed-off-by: goenning --- kube-core/src/request.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/kube-core/src/request.rs b/kube-core/src/request.rs index 21805f72d..13416c39d 100644 --- a/kube-core/src/request.rs +++ b/kube-core/src/request.rs @@ -738,10 +738,7 @@ mod test { let url = corev1::Pod::url_path(&(), Some("ns")); let gp = ListParams::default().limit(50).match_any(); let req = Request::new(url).list(&gp).unwrap(); - assert_eq!( - req.uri().query().unwrap(), - "&limit=50" - ); + assert_eq!(req.uri().query().unwrap(), "&limit=50"); } #[test] @@ -749,21 +746,19 @@ mod test { let url = corev1::Pod::url_path(&(), Some("ns")); let gp = ListParams::default().limit(50).continue_token("1234").match_any(); let req = Request::new(url).list(&gp).unwrap(); - assert_eq!( - req.uri().query().unwrap(), - "&limit=50&continue=1234" - ); + assert_eq!(req.uri().query().unwrap(), "&limit=50&continue=1234"); } #[test] fn list_paged_with_continue_starting_at() { let url = corev1::Pod::url_path(&(), Some("ns")); - let gp = ListParams::default().limit(50).continue_token("1234").at("9999").matching(VersionMatch::Exact); + let gp = ListParams::default() + .limit(50) + .continue_token("1234") + .at("9999") + .matching(VersionMatch::Exact); let req = Request::new(url).list(&gp).unwrap(); - assert_eq!( - req.uri().query().unwrap(), - "&limit=50&continue=1234" - ); + assert_eq!(req.uri().query().unwrap(), "&limit=50&continue=1234"); } #[test]