Documentation
¶
Overview ¶
Package state provides utilities for container state management
Index ¶
- Variables
- type ContainerInfo
- type ContainerState
- type Manager
- func (m *Manager) GetContainerInfo(containerID string) (*ContainerInfo, error)
- func (m *Manager) GetState(containerID string) (ContainerState, error)
- func (m *Manager) IsValidTransition(fromState, toState ContainerState) bool
- func (m *Manager) ListContainers() map[string]ContainerState
- func (m *Manager) RegisterStateChangeHandler(state ContainerState, handler StateChangeHandler)
- func (m *Manager) StartWatching() error
- func (m *Manager) StopWatching()
- func (m *Manager) UpdateState(containerID string, state ContainerState) error
- type StateChangeHandler
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidStateTransition = errors.New("invalid container state transition")
ErrInvalidStateTransition is returned when a state transition is invalid
var ValidStateTransitions = map[ContainerState][]ContainerState{ StateCreated: {StateRunning, StateExited}, StateRunning: {StatePaused, StateExited, StateRestarting, StateRemoving}, StatePaused: {StateRunning, StateRemoving}, StateRestarting: {StateRunning, StateExited}, StateExited: {StateRunning, StateRemoving}, StateDead: {StateRemoving}, StateRemoving: {}, StateUnknown: ValidStates, }
ValidStateTransitions defines the valid state transitions for containers
var ValidStates = []ContainerState{ StateCreated, StateRunning, StatePaused, StateRestarting, StateRemoving, StateExited, StateDead, StateUnknown, }
ValidStates is a list of all valid container states
Functions ¶
This section is empty.
Types ¶
type ContainerInfo ¶
type ContainerInfo struct {
ID string
Name string
CurrentState ContainerState
PreviousState ContainerState
ExitCode int
LastUpdated time.Time
StartedAt time.Time
FinishedAt time.Time
Error string
RestartCount int
HealthStatus string
}
ContainerInfo holds information about a container
type ContainerState ¶
type ContainerState string
ContainerState represents the possible states of a container
const ( // StateCreated represents a created container StateCreated ContainerState = "created" // StateRunning represents a running container StateRunning ContainerState = "running" // StatePaused represents a paused container StatePaused ContainerState = "paused" // StateRestarting represents a restarting container StateRestarting ContainerState = "restarting" // StateRemoving represents a container being removed StateRemoving ContainerState = "removing" // StateExited represents an exited container StateExited ContainerState = "exited" // StateDead represents a dead container StateDead ContainerState = "dead" // StateUnknown represents an unknown container state StateUnknown ContainerState = "unknown" )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages container state tracking and transitions
func NewManager ¶
NewManager creates a new container state manager
func (*Manager) GetContainerInfo ¶
func (m *Manager) GetContainerInfo(containerID string) (*ContainerInfo, error)
GetContainerInfo gets information about a container
func (*Manager) GetState ¶
func (m *Manager) GetState(containerID string) (ContainerState, error)
GetState gets the current state of a container
func (*Manager) IsValidTransition ¶
func (m *Manager) IsValidTransition(fromState, toState ContainerState) bool
IsValidTransition checks if a state transition is valid
func (*Manager) ListContainers ¶
func (m *Manager) ListContainers() map[string]ContainerState
ListContainers lists all tracked containers and their states
func (*Manager) RegisterStateChangeHandler ¶
func (m *Manager) RegisterStateChangeHandler(state ContainerState, handler StateChangeHandler)
RegisterStateChangeHandler registers a callback for a specific state transition
func (*Manager) StartWatching ¶
StartWatching starts watching for container state changes
func (*Manager) StopWatching ¶
func (m *Manager) StopWatching()
StopWatching stops watching for container state changes
func (*Manager) UpdateState ¶
func (m *Manager) UpdateState(containerID string, state ContainerState) error
UpdateState updates the state of a container
type StateChangeHandler ¶
type StateChangeHandler func(containerID string, oldState, newState ContainerState, info *ContainerInfo)
StateChangeHandler is a callback for state changes