events

package
v0.8.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package events owns event recording. Kubernetes events are the primary observability surface for reconciliation progress — they appear in kubectl describe output and are consumed by monitoring tooling. Every domain stage that succeeds or fails emits an event via EventRecorder.

EventRecorder abstracts over two client-go recorder APIs:

  • recordv1 (client-go/tools/record): the legacy recorder, returned by mgr.GetEventRecorder(). Used by most controller-runtime setups today.
  • eventsv1 (client-go/tools/events): the structured recorder backed by the v1 Events API. More expressive but less commonly wired at setup time.

Both are supported transparently — the caller uses the same Normal/Warn/Info surface regardless of which recorder was injected. A nil or empty recorder is always safe; all methods guard against nil receivers and nil objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventRecorder

type EventRecorder struct {
	// contains filtered or unexported fields
}

EventRecorder wraps both client-go recorder APIs behind a unified interface. Domains call Normal, Warn, Info, FromError — never the underlying recorders directly. This keeps domain code decoupled from the recorder implementation and safe against nil recorders at setup time.

func NewEventRecorder

func NewEventRecorder(rec interface{}) *EventRecorder

NewEventRecorder constructs an EventRecorder from either recorder type. Accepts recordv1.EventRecorder or eventsv1.EventRecorder — the concrete type is detected at construction time and stored in the appropriate field. An unrecognised input returns a no-op recorder so callers are always safe.

func (*EventRecorder) Event

func (er *EventRecorder) Event(
	obj client.Object,
	eventType string,
	reason string,
	msg string,
	args ...interface{},
)

Event emits a Kubernetes event on obj with the given eventType, reason, and formatted message. Dispatches to whichever underlying recorder is populated.

Safe to call with a nil receiver or nil obj — both are no-ops. Domains should prefer Normal, Warn, Info, and FromError over calling Event directly.

func (*EventRecorder) FromError

func (er *EventRecorder) FromError(
	obj client.Object,
	reason string,
	err error,
)

FromError emits a Warning event with the error message as the note. No-op when err is nil. The standard call site in domain Handle methods:

d.events.FromError(buildCR, "BuildResolveFailed", err)

func (*EventRecorder) FromErrorf

func (er *EventRecorder) FromErrorf(
	obj client.Object,
	reason string,
	err error,
	msg string,
	args ...interface{},
)

FromErrorf emits a Warning event combining a context message and the error. No-op when err is nil. Use when the error alone lacks enough context for an operator reading kubectl describe output.

d.events.FromErrorf(buildCR, "BuildPrerequisitesFailed", err, "namespace %s", ns)

func (*EventRecorder) Info

func (er *EventRecorder) Info(
	obj client.Object,
	reason string,
	msg string,
	args ...interface{},
)

Info is an alias for Normal. Used at call sites where "informational" reads more naturally than "normal" (e.g. deletion acknowledgements).

func (*EventRecorder) Normal

func (er *EventRecorder) Normal(
	obj client.Object,
	reason string,
	msg string,
	args ...interface{},
)

Normal emits a Normal-type event on obj. Used for successful stage transitions in the reconciliation pipeline.

func (*EventRecorder) Warn

func (er *EventRecorder) Warn(
	obj client.Object,
	reason string,
	msg string,
	args ...interface{},
)

Warn emits a Warning-type event on obj. Used for failed stage transitions and error conditions in the reconciliation pipeline.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL