From 0326f00cd6d756bde8b9cf0185965832eae5dc87 Mon Sep 17 00:00:00 2001 From: clux Date: Wed, 7 Dec 2022 04:19:28 +0000 Subject: [PATCH 1/2] Gracefully error in watcher when kinds do not support watch Closes #1092 Signed-off-by: clux --- kube-runtime/src/watcher.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kube-runtime/src/watcher.rs b/kube-runtime/src/watcher.rs index be2ac092c..8662ff12f 100644 --- a/kube-runtime/src/watcher.rs +++ b/kube-runtime/src/watcher.rs @@ -25,6 +25,8 @@ pub enum Error { WatchError(#[source] kube_client::error::ErrorResponse), #[error("watch stream failed: {0}")] WatchFailed(#[source] kube_client::Error), + #[error("No metadata.resourceVersion in watch result (does kind support watch?)")] + NoResourceVersion, #[error("too many objects matched search criteria")] TooManyObjects, } @@ -139,9 +141,15 @@ async fn step_trampolined (Option>>, State) { match state { State::Empty => match api.list(list_params).await { - Ok(list) => (Some(Ok(Event::Restarted(list.items))), State::InitListed { - resource_version: list.metadata.resource_version.unwrap(), - }), + Ok(list) => { + if let Some(resource_version) = list.metadata.resource_version { + (Some(Ok(Event::Restarted(list.items))), State::InitListed { + resource_version, + }) + } else { + (Some(Err(Error::NoResourceVersion)), State::Empty) + } + } Err(err) => (Some(Err(err).map_err(Error::InitialListFailed)), State::Empty), }, State::InitListed { resource_version } => match api.watch(list_params, &resource_version).await { From 84acf2b6cd16123a129d81fee32f7c7554ff5305 Mon Sep 17 00:00:00 2001 From: Eirik A Date: Wed, 7 Dec 2022 10:05:31 +0000 Subject: [PATCH 2/2] Update kube-runtime/src/watcher.rs Co-authored-by: teozkr Signed-off-by: Eirik A --- kube-runtime/src/watcher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube-runtime/src/watcher.rs b/kube-runtime/src/watcher.rs index 8662ff12f..020a5f20b 100644 --- a/kube-runtime/src/watcher.rs +++ b/kube-runtime/src/watcher.rs @@ -25,7 +25,7 @@ pub enum Error { WatchError(#[source] kube_client::error::ErrorResponse), #[error("watch stream failed: {0}")] WatchFailed(#[source] kube_client::Error), - #[error("No metadata.resourceVersion in watch result (does kind support watch?)")] + #[error("no metadata.resourceVersion in watch result (does resource support watch?)")] NoResourceVersion, #[error("too many objects matched search criteria")] TooManyObjects,