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§

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.

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more