Skip to content

Commit

Permalink
core: omit invalid resource version parameters when doing paged req…
Browse files Browse the repository at this point in the history
…uests (#1281)

* fix paging parameters when using any semantic

Signed-off-by: goenning <me@goenning.net>

* fmt

Signed-off-by: goenning <me@goenning.net>

---------

Signed-off-by: goenning <me@goenning.net>
Co-authored-by: Eirik A <sszynrae@gmail.com>
  • Loading branch information
goenning and clux committed Aug 22, 2023
1 parent 3af6b7f commit f44ce00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 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
29 changes: 22 additions & 7 deletions kube-core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,31 @@ mod test {
}

#[test]
fn list_not_older() {
fn list_paged_any_semantic() {
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");
}

#[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()
.at("20")
.matching(VersionMatch::NotOlderThan);
.limit(50)
.continue_token("1234")
.at("9999")
.matching(VersionMatch::Exact);
let req = Request::new(url).list(&gp).unwrap();
assert_eq!(
req.uri().query().unwrap(),
"&resourceVersion=20&resourceVersionMatch=NotOlderThan"
);
assert_eq!(req.uri().query().unwrap(), "&limit=50&continue=1234");
}

#[test]
Expand Down

0 comments on commit f44ce00

Please sign in to comment.