events

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package events provides a thread-safe event bus for the Doki daemon.

It mirrors the semantics of the Docker /events endpoint and the Podman /libpod/events endpoint: subscribers receive a continuous stream of typed events, optionally filtered by type/event/labels. Subscribers can be removed at any time without affecting other subscribers. The bus is the single source of truth for all container/image/network/volume/system lifecycle notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action is the specific action that occurred. Values are the canonical Moby/Podman strings ("start", "die", "create", ...).

const (
	ActionCreate     Action = "create"
	ActionStart      Action = "start"
	ActionStop       Action = "stop"
	ActionDie        Action = "die"
	ActionKill       Action = "kill"
	ActionPause      Action = "pause"
	ActionUnpause    Action = "unpause"
	ActionRestart    Action = "restart"
	ActionDestroy    Action = "destroy"
	ActionRemove     Action = "destroy"
	ActionRename     Action = "rename"
	ActionResize     Action = "resize"
	ActionArchive    Action = "archive"
	ActionExport     Action = "export"
	ActionImport     Action = "import"
	ActionPull       Action = "pull"
	ActionPush       Action = "push"
	ActionTag        Action = "tag"
	ActionUntag      Action = "untag"
	ActionDelete     Action = "delete"
	ActionConnect    Action = "connect"
	ActionDisconnect Action = "disconnect"
	ActionPrune      Action = "prune"
	ActionHealth     Action = "health_status"
	ActionOOM        Action = "oom"
	ActionExec       Action = "exec_create"
	ActionExecDie    Action = "exec_die"
)

type Actor

type Actor struct {
	ID         string            `json:"ID"`
	Attributes map[string]string `json:"Attributes,omitempty"`
}

Actor is the object the event refers to.

type Bus

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

Bus is the central event multiplexer.

func NewBus

func NewBus() *Bus

NewBus creates an empty bus.

func (*Bus) Close

func (b *Bus) Close()

Close shuts down the bus and closes all subscriber channels.

func (*Bus) Count

func (b *Bus) Count() int

Count returns the number of active subscribers.

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish sends an event to all matching subscribers. It never blocks and never returns an error: if a subscriber's buffer is full, the event is dropped for that subscriber (and the bus increments a per-subscriber drop counter visible via Stats).

func (*Bus) PublishContainer

func (b *Bus) PublishContainer(action Action, id, name string, attrs map[string]string)

PublishContainer is a convenience for container events.

func (*Bus) PublishImage

func (b *Bus) PublishImage(action Action, id string, attrs map[string]string)

PublishImage publishes an image event.

func (*Bus) PublishNetwork

func (b *Bus) PublishNetwork(action Action, id, name string)

PublishNetwork publishes a network event.

func (*Bus) PublishPod

func (b *Bus) PublishPod(action Action, id, name string)

PublishPod publishes a pod event.

func (*Bus) PublishSystem

func (b *Bus) PublishSystem(action Action, attrs map[string]string)

PublishSystem publishes a system-level event.

func (*Bus) PublishVolume

func (b *Bus) PublishVolume(action Action, name string)

PublishVolume publishes a volume event.

func (*Bus) Subscribe

func (b *Bus) Subscribe(f Filter, bufferSize int) *Subscription

Subscribe registers a new subscriber with the given filter and buffer size. Buffer size 0 means unbuffered; otherwise the channel will buffer up to bufferSize events before dropping the slowest subscribers' messages (publishing is non-blocking).

func (*Bus) SubscribeContext

func (b *Bus) SubscribeContext(ctx context.Context, f Filter, bufferSize int) *Subscription

SubscribeContext is like Subscribe but additionally closes the subscription when ctx is cancelled.

type Event

type Event struct {
	Type       Type              `json:"Type"`
	Action     Action            `json:"Action"`
	Actor      Actor             `json:"Actor"`
	Status     string            `json:"status,omitempty"`
	ID         string            `json:"id,omitempty"`
	From       string            `json:"from,omitempty"`
	Time       int64             `json:"time"`
	TimeNano   int64             `json:"timeNano"`
	Scope      string            `json:"scope,omitempty"`
	Attributes map[string]string `json:"Actor.Attributes,omitempty"`
}

Event is a single lifecycle notification.

func (Event) ToJSON

func (e Event) ToJSON() ([]byte, error)

ToJSON returns a JSON-encoded representation suitable for /events.

type Filter

type Filter struct {
	Type      []string `json:"type,omitempty"`
	Event     []string `json:"event,omitempty"`
	Container []string `json:"container,omitempty"`
	Image     []string `json:"image,omitempty"`
	Network   []string `json:"network,omitempty"`
	Volume    []string `json:"volume,omitempty"`
	Pod       []string `json:"pod,omitempty"`
	Label     []string `json:"label,omitempty"`
}

Filter narrows the events a subscriber receives. Each non-empty field is AND-combined; each list within a field is OR-combined.

func FilterFromJSON

func FilterFromJSON(data []byte) (Filter, error)

FilterFromJSON parses a Docker-style filter JSON. The format is a map of arrays of strings: `{"status":["running"],"label":["a=b"]}`.

type Subscription

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

Subscription is a handle returned by Subscribe that the caller must Close() to stop receiving events.

func (*Subscription) Channel

func (s *Subscription) Channel() <-chan Event

Channel returns the receive-only channel for events.

func (*Subscription) Close

func (s *Subscription) Close() error

Close releases the subscription. Idempotent.

func (*Subscription) ID

func (s *Subscription) ID() uint64

ID returns the subscription's unique identifier.

type Type

type Type string

Type is the high-level event category.

const (
	TypeContainer Type = "container"
	TypeImage     Type = "image"
	TypeNetwork   Type = "network"
	TypeVolume    Type = "volume"
	TypePod       Type = "pod"
	TypeSecret    Type = "secret"
	TypeSystem    Type = "system"
	TypeBuilder   Type = "builder"
)

Jump to

Keyboard shortcuts

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