Documentation
¶
Overview ¶
Package events provides a Recorder and additional helpers to record Kubernetes Events on an external HTTP endpoint.
Index ¶
Constants ¶
const ( // EventSeverityTrace represents a trace event, usually // informing about actions taken during reconciliation. EventSeverityTrace string = "trace" // EventSeverityInfo represents an informational event, usually // informing about changes. EventSeverityInfo string = "info" // EventSeverityError represent an error event, usually a warning // that something goes wrong. EventSeverityError string = "error" )
These constants define valid event severity values.
const EventTypeTrace string = "Trace"
EventTypeTrace represents a trace event.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// The object that this event is about.
// +required
InvolvedObject corev1.ObjectReference `json:"involvedObject"`
// Severity type of this event (trace, info, error)
// +kubebuilder:validation:Enum=trace;info;error
// +required
Severity string `json:"severity"`
// The time at which this event was recorded.
// +required
Timestamp metav1.Time `json:"timestamp"`
// A human-readable description of this event.
// Maximum length 39,000 characters.
// +kubebuilder:validation:MaxLength=39000
// +required
Message string `json:"message"`
// A machine understandable string that gives the reason
// for the transition into the object's current status.
// +required
Reason string `json:"reason"`
// Metadata of this event, e.g. apply change set.
// +optional
Metadata map[string]string `json:"metadata,omitempty"`
// Name of the controller that emitted this event, e.g. `source-controller`.
// +required
ReportingController string `json:"reportingController"`
// ID of the controller instance, e.g. `source-controller-xyzf`.
// +optional
ReportingInstance string `json:"reportingInstance,omitempty"`
}
Event is a report of an event issued by a controller. +kubebuilder:object:generate=true
func (*Event) DeepCopy ¶ added in v0.9.0
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Event.
func (*Event) DeepCopyInto ¶ added in v0.9.0
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
type Recorder ¶
type Recorder struct {
// URL address of the events endpoint.
Webhook string
// Name of the controller that emits events.
ReportingController string
// Retryable HTTP client.
Client *retryablehttp.Client
// EventRecorder is the Kubernetes event recorder.
EventRecorder kuberecorder.EventRecorder
// Scheme to look up the recorded objects.
Scheme *runtime.Scheme
// Log is the recorder logger.
Log logr.Logger
}
Recorder posts events to the Kubernetes API and any other event recorder webhook address, like the GitOps Toolkit notification-controller.
Use it by embedding EventRecorder in reconciler struct:
import (
...
kuberecorder "k8s.io/client-go/tools/record"
...
)
type MyTypeReconciler {
client.Client
// ... etc.
kuberecorder.EventRecorder
}
Use NewRecorder to create a working Recorder.
func NewRecorder ¶
func NewRecorder(mgr ctrl.Manager, log logr.Logger, webhook, reportingController string) (*Recorder, error)
NewRecorder creates an event Recorder with a Kubernetes event recorder and an external event recorder based on the given webhook. The recorder performs automatic retries for connection errors and 500-range response codes from the external recorder.
func (*Recorder) AnnotatedEventf ¶ added in v0.13.0
func (r *Recorder) AnnotatedEventf( object runtime.Object, annotations map[string]string, eventtype, reason string, messageFmt string, args ...interface{})
AnnotatedEventf constructs an event from the given information and performs a HTTP POST to the webhook address. It also logs the event if debug logs are enabled in the logger.