Skip to content

Commit

Permalink
Always reset the Informer version to 0
Browse files Browse the repository at this point in the history
Takes "approach 2" from
kube-rs#134 (comment), see the noted
caveats.

Deletes Informer::init, since it is no longer useful.
  • Loading branch information
nightkr committed Feb 26, 2020
1 parent d2f7bdf commit 54f06cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.27.0 / 2020-02-XX
===================
* `Reflector` + `Informer` moved from `kube::api` to `kube::runtime`
* `Informer` now resets the version to 0 rather than dropping events - #134
* Removed `Informer::init`, since it is now a no-op when building the `Informer`

0.26.0 / 2020-02-25
===================
Expand Down
34 changes: 5 additions & 29 deletions src/runtime/informer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ where

// finalizers:

/// Initialize without a prior version
///
/// Will seed resourceVersion with a 1 limit list call to the resource
pub async fn init(self) -> Result<Self> {
info!("Starting Informer for {:?}", self.resource);
self.reset().await?;
Ok(self)
}

/// Initialize from a prior version
pub fn init_from(self, v: String) -> Self {
info!("Recreating Informer for {:?} at {}", self.resource, v);
Expand Down Expand Up @@ -212,11 +203,11 @@ where
}
}

/// Reset the resourceVersion to latest
pub async fn reset(&self) -> Result<()> {
let latest = self.get_resource_version().await?;
*self.version.lock().await = latest;
Ok(())
/// Reset the resourceVersion to 0
///
/// Note: This will cause duplicate Added events for all existing resources
pub async fn reset(&self) {
*self.version.lock().await = 0.to_string();
}

/// Return the current version
Expand All @@ -225,19 +216,4 @@ where
// to get a lock on our version
futures::executor::block_on(async { self.version.lock().await.clone() })
}

/// Init helper
async fn get_resource_version(&self) -> Result<String> {
let req = self.resource.list_zero_resource_entries(&self.params)?;

// parse to void a ResourceList into void except for Metadata
let res = self.client.request::<ObjectList<NotUsed>>(req).await?;

let version = res.metadata.resourceVersion.unwrap_or_else(|| "0".into());
debug!(
"Got fresh resourceVersion={} for {}",
version, self.resource.resource
);
Ok(version)
}
}

0 comments on commit 54f06cd

Please sign in to comment.