Skip to content

Commit

Permalink
fix paging parameters when using any semantic
Browse files Browse the repository at this point in the history
Signed-off-by: goenning <me@goenning.net>
  • Loading branch information
goenning committed Aug 19, 2023
1 parent 5e98a92 commit 1d73dd1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
28 changes: 16 additions & 12 deletions kube-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
}
}
Expand Down
30 changes: 25 additions & 5 deletions kube-core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand Down

0 comments on commit 1d73dd1

Please sign in to comment.