pub struct LeaseManager { /* private fields */ }lease only.Expand description
Manages a Kubernetes Lease
Implementations§
Source§impl LeaseManager
impl LeaseManager
Sourcepub async fn init(api: Api<Lease>, name: impl ToString) -> Result<Self, Error>
pub async fn init(api: Api<Lease>, name: impl ToString) -> Result<Self, Error>
Initialize a lease’s state from the Kubernetes API.
The named lease resource must already have been created, or a 404 error will be returned.
Sourcepub fn with_field_manager(
self,
field_manager: impl Into<Cow<'static, str>>,
) -> Self
pub fn with_field_manager( self, field_manager: impl Into<Cow<'static, str>>, ) -> Self
Overrides the field manager used when updating the Lease
This is intended to be used immediately following initialization and
before ensure_claimed is invoked.
Sourcepub async fn claimed(&self) -> Option<Arc<Claim>>
pub async fn claimed(&self) -> Option<Arc<Claim>>
Return the state of the claim without updating it from the API.
Sourcepub async fn sync(&self) -> Result<Option<Arc<Claim>>, Error>
pub async fn sync(&self) -> Result<Option<Arc<Claim>>, Error>
Update the state of the claim from the API.
Sourcepub async fn ensure_claimed(
&self,
claimant: &str,
params: &ClaimParams,
) -> Result<Arc<Claim>, Error>
pub async fn ensure_claimed( &self, claimant: &str, params: &ClaimParams, ) -> Result<Arc<Claim>, Error>
Ensures that the lease, if it exists, is claimed.
If these is not currently held, it is claimed by the provided identity. If it is currently held by the provided claimant, it is renewed if it is within the renew grace period.
Sourcepub async fn vacate(&self, claimant: &str) -> Result<bool, Error>
pub async fn vacate(&self, claimant: &str) -> Result<bool, Error>
Clear out the state of the lease if the claim is currently held by the provided identity.
This is typically used during process shutdown so that another process can potentially claim the lease before the prior lease duration expires.
Sourcepub async fn spawn(
self,
claimant: impl ToString,
params: ClaimParams,
) -> Result<(Receiver<Arc<Claim>>, JoinHandle<Result<(), Error>>), Error>
pub async fn spawn( self, claimant: impl ToString, params: ClaimParams, ) -> Result<(Receiver<Arc<Claim>>, JoinHandle<Result<(), Error>>), Error>
Spawn a task that ensures the lease is claimed.
When the lease becomes unclaimed, the task attempts to claim the lease as claimant and maintains the lease until the task completes or the lease is claimed by another process.
The state of the lease is published via the returned receiver.
When all receivers are dropped, the task completes and the lease is vacated so that another process can claim it.
Auto Trait Implementations§
impl !Freeze for LeaseManager
impl !RefUnwindSafe for LeaseManager
impl Send for LeaseManager
impl Sync for LeaseManager
impl Unpin for LeaseManager
impl !UnwindSafe for LeaseManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more