pub struct Controller<Ctx>where
Ctx: Send + Sync + 'static + Context,
Ctx::Error: Send + Sync + 'static,
for<'de> Ctx::Resource: Send + Sync + 'static + Clone + Debug + Serialize + Deserialize<'de>,
<Ctx::Resource as Resource>::DynamicType: Eq + Clone + Hash + Default + Debug + Unpin,{ /* private fields */ }Expand description
The Controller watches a set of resources, calling methods on the
provided Context when events occur.
Implementations§
Source§impl<Ctx> Controller<Ctx>
impl<Ctx> Controller<Ctx>
Sourcepub fn namespaced(
client: Client,
context: Ctx,
namespace: &str,
wc: Config,
) -> Self
pub fn namespaced( client: Client, context: Ctx, namespace: &str, wc: Config, ) -> Self
Creates a new controller for a namespaced resource using the given
client. The context given determines the type of resource
to watch (via the Context::Resource type provided as part of
the trait implementation). The resources to be watched will be
limited to resources in the given namespace. A watcher::Config
can be given to limit the resources watched (for instance,
watcher::Config::default().labels("app=myapp")).
Sourcepub fn namespaced_all(client: Client, context: Ctx, wc: Config) -> Self
pub fn namespaced_all(client: Client, context: Ctx, wc: Config) -> Self
Creates a new controller for a namespaced resource using the given
client. The context given determines the type of resource to
watch (via the Context::Resource type provided as part of the
trait implementation). The resources to be watched will not be
limited by namespace. A watcher::Config can be given to limit the
resources watched (for instance,
watcher::Config::default().labels("app=myapp")).
Sourcepub fn cluster(client: Client, context: Ctx, wc: Config) -> Self
pub fn cluster(client: Client, context: Ctx, wc: Config) -> Self
Creates a new controller for a cluster-scoped resource using the
given client. The context given determines the type of resource
to watch (via the Context::Resource type provided as part of the
trait implementation). A watcher::Config can be given to limit the
resources watched (for instance,
watcher::Config::default().labels("app=myapp")).
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Sets the name identifying this controller in its metrics (the
controller field of ReconcileRecord and
StepRecord), and in the controller field of
its reconcile tracing span. Defaults to Context::FINALIZER_NAME
if set, and otherwise to the kind of the resource being watched.
Controllers sharing an observer must have distinct names, or their metrics will be merged.
Sourcepub fn with_observer(self, observer: Arc<dyn ReconcileObserver>) -> Self
pub fn with_observer(self, observer: Arc<dyn ReconcileObserver>) -> Self
Sourcepub fn with_event_recorder(self, events: Arc<EventRecorder>) -> Self
pub fn with_event_recorder(self, events: Arc<EventRecorder>) -> Self
Publishes a Kubernetes event on the resource whenever reconciling it
fails, as determined by Context::failure_event, and enables
TraceMetadata::publish_event for the context’s own events. See
the events module, including for the RBAC
permissions this requires.
events must not be given to any other controller. Besides every
event appearing to come from the same controller, a successful pass
of one controller would reset the aggregation of another’s failure
events for the same resource.
Sourcepub async fn run(self)
pub async fn run(self)
Run the controller. This method will not return. The Context
given to the constructor will have its apply
method called when a resource is created or updated, and its
cleanup method called when a resource is about
to be deleted.
To run multiple replicas of a controller with only one reconciling
at a time, pass this method’s future to
LeaderElection::with_lease.
Sourcepub fn with_controller<F>(self, f: F) -> Self
pub fn with_controller<F>(self, f: F) -> Self
Allow configuring the underlying kube_runtime::Controller. For
example, you can use
controller.with_controller(|controller| controller.with_config(Config::default().concurrency(10)))
to limit the created controller to reconciling 10 resources at once.
Auto Trait Implementations§
impl<Ctx> !Freeze for Controller<Ctx>
impl<Ctx> !RefUnwindSafe for Controller<Ctx>
impl<Ctx> !Sync for Controller<Ctx>
impl<Ctx> !UnwindSafe for Controller<Ctx>
impl<Ctx> Send for Controller<Ctx>
impl<Ctx> Unpin for Controller<Ctx>
impl<Ctx> UnsafeUnpin for Controller<Ctx>where
<<Ctx as Context>::Resource as Resource>::DynamicType: Sized,
<Ctx as Context>::Resource: for<'de> Sized,
Box<dyn Fn(&<Ctx as Context>::Resource) -> Api<<Ctx as Context>::Resource> + Sync + Send>: UnsafeUnpin,
Controller<<Ctx as Context>::Resource>: UnsafeUnpin,
Ctx: UnsafeUnpin,
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