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§
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.