From cde4530d94dca9044f928d0eb1b3fe1fb4c60a49 Mon Sep 17 00:00:00 2001 From: Eirik A Date: Fri, 9 Dec 2022 04:49:37 +0000 Subject: [PATCH] Return error from `watcher` when kinds do not support watch (#1101) * Gracefully error in watcher when kinds do not support watch Closes #1092 Signed-off-by: clux * Update kube-runtime/src/watcher.rs Co-authored-by: teozkr Signed-off-by: Eirik A Signed-off-by: clux Signed-off-by: Eirik A Co-authored-by: teozkr --- 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..020a5f20b 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 resource 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 {