pub struct Recorder { /* private fields */ }
Expand description
A publisher abstraction to emit Kubernetes’ events.
All events emitted by an Recorder
are attached to the ObjectReference
specified when building the recorder using Recorder::new
.
use kube::runtime::events::{Reporter, Recorder, Event, EventType};
use k8s_openapi::api::core::v1::ObjectReference;
let reporter = Reporter {
controller: "my-awesome-controller".into(),
instance: std::env::var("CONTROLLER_POD_NAME").ok(),
};
// references can be made manually using `ObjectMeta` and `ApiResource`/`Resource` info
let reference = ObjectReference {
// [...]
..Default::default()
};
// or for k8s-openapi / kube-derive types, use Resource::object_ref:
// let reference = myobject.object_ref();
let recorder = Recorder::new(client, reporter, reference);
recorder.publish(Event {
action: "Scheduling".into(),
reason: "Pulling".into(),
note: Some("Pulling image `nginx`".into()),
type_: EventType::Normal,
secondary: None,
}).await?;
Events attached to an object will be shown in the Events
section of the output of
of kubectl describe
for that object.
§RBAC
Note that usage of the event recorder minimally requires the following RBAC rules:
- apiGroups: ["events.k8s.io"]
resources: ["events"]
verbs: ["create"]
Implementations§
Source§impl Recorder
impl Recorder
Sourcepub fn new(
client: Client,
reporter: Reporter,
reference: ObjectReference,
) -> Self
pub fn new( client: Client, reporter: Reporter, reference: ObjectReference, ) -> Self
Create a new recorder that can publish events for one specific object
This is intended to be created at the start of your controller’s reconcile fn.
Cluster scoped objects will publish events in the “default” namespace.
Sourcepub async fn publish(&self, ev: Event) -> Result<(), Error>
pub async fn publish(&self, ev: Event) -> Result<(), Error>
Publish a new Kubernetes’ event.
§Access control
The event object is created in the same namespace of the ObjectReference
you specified in Recorder::new
.
Make sure that your controller has create
permissions in the required namespaces
for the event
resource in the API group events.k8s.io
.
§Errors
Returns an Error
if the event is rejected by Kubernetes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Recorder
impl !RefUnwindSafe for Recorder
impl Send for Recorder
impl Sync for Recorder
impl Unpin for Recorder
impl !UnwindSafe for Recorder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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