Struct kube_runtime::events::Recorder
source · [−]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::{
core::Resource,
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.
Implementations
sourceimpl 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 createad at the start of your controller’s reconcile fn.
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 !RefUnwindSafe for Recorder
impl Send for Recorder
impl Sync for Recorder
impl Unpin for Recorder
impl !UnwindSafe for Recorder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more