kubert::lease

Struct LeaseManager

Source
pub struct LeaseManager { /* private fields */ }
Available on crate feature lease only.
Expand description

Manages a Kubernetes Lease

Implementations§

Source§

impl LeaseManager

Source

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.

Source

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.

Source

pub async fn claimed(&self) -> Option<Arc<Claim>>

Return the state of the claim without updating it from the API.

Source

pub async fn sync(&self) -> Result<Option<Arc<Claim>>, Error>

Update the state of the claim from the API.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more