Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watcher: return NoResourceVersion error if resource version is empty #1259

Merged
merged 1 commit into from Jul 20, 2023

Conversation

aryan9600
Copy link
Contributor

@aryan9600 aryan9600 commented Jul 19, 2023

Motivation

Atm, the watcher don't check if the returned resource version is empty before taking its next step, which effectively makes it a hard error (potential panics since we use unwrap() in some places). Instead of treating them as hard errors, we should bubble them up.

Solution

Check if resource version returned by the API to the watcher is empty and return a NoResourceVersion error if it is.

Fixes #1251

Check if resource version returned by the API to the watcher is empty
and return a `NoResourceVersion` error if it is.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #1259 (711eccd) into main (7e8b509) will decrease coverage by 0.03%.
The diff coverage is 78.57%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1259      +/-   ##
==========================================
- Coverage   73.19%   73.16%   -0.03%     
==========================================
  Files          75       75              
  Lines        6025     6030       +5     
==========================================
+ Hits         4410     4412       +2     
- Misses       1615     1618       +3     
Impacted Files Coverage Δ
kube-runtime/src/watcher.rs 48.21% <78.57%> (-0.26%) ⬇️

@clux clux added the changelog-fix changelog fix category for prs label Jul 19, 2023
@clux clux added this to the 0.85.0 milestone Jul 19, 2023
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Nice and simple. One of the last unwrap assumptions in the runtime gone 👍

Left a comment on a potential error case this could in theory introduce, but I feel it's probably not anything worth worrying about.

Comment on lines +472 to +474
let resource_version = obj.resource_version().unwrap_or_default();
if resource_version.is_empty() {
(Some(Err(Error::NoResourceVersion)), State::default())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor observation here. Before this change in the watching stage, we would actually be somewhat resilient to missing resource versions here (where resource versions got transmitted as empty strings) because the resource version is only used in the next watch, and Kubernetes seem to accept empty strings in the watch params 🙃

It is technically possible that this change will lead to more re-lists because of some apiserver returning "" as resource versions. Still, that's kind of an impossibly defensive game to play against what is meant to be a stable api, so it's probably best to assume they are reasonably well behaved here, and raise bugs upstream otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its theoretically possible, but as far as i'm aware, this should practically not happen since the resource version in the response is never blank. From https://kubernetes.io/docs/reference/using-api/api-concepts/#resourceversion-in-metadata:

v1.meta/ListMeta - The metadata.resourceVersion of a resource collection (the response to a list) identifies the resource version at which the collection was constructed.

@clux clux merged commit 52a16ec into kube-rs:main Jul 20, 2023
16 checks passed
@clux clux changed the title return NoResourceVersion error if resource version is empty watcher: return NoResourceVersion error if resource version is empty Jul 21, 2023
@clux clux added the runtime controller runtime related label Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-fix changelog fix category for prs runtime controller runtime related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strengthen resource_version handling in watcher
2 participants