Documentation
¶
Overview ¶
Package sorter provides sorting functionality for Watchtower containers. It implements dependency-based topological sorting and creation time ordering.
Key components:
- SortByDependencies: Sorts containers in place by links, detecting circular references.
- SortByCreated: Sorts containers in place by creation time with fallback to current time.
- Sorter: Common interface for all sorting implementations.
Usage example:
err := sorter.SortByDependencies(containers)
if err != nil {
logrus.WithError(err).Error("Dependency sort failed")
}
err = sorter.SortByCreated(containers)
if err != nil {
logrus.WithError(err).Error("Time sort failed")
}
The package uses logrus for logging sort operations and errors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCircularReference = errors.New("circular reference detected")
ErrCircularReference indicates a circular dependency between containers.
var ErrIdentifierCollision = errors.New("identifier collision detected")
ErrIdentifierCollision indicates an identifier collision between containers.
Functions ¶
func SortByCreated ¶
SortByCreated sorts containers in place by creation time.
Parameters:
- containers: Slice to sort in place.
Returns:
- error: propagated from TimeSorter.Sort.
func SortByDependencies ¶
SortByDependencies sorts containers in place by dependencies.
Parameters:
- containers: Slice to sort in place.
Returns:
- error: Non-nil if circular reference detected, nil on success.
Types ¶
type CircularReferenceError ¶
CircularReferenceError represents a circular dependency error with the container name and cycle path.
func (CircularReferenceError) Error ¶
func (e CircularReferenceError) Error() string
Error implements the error interface.
func (CircularReferenceError) Unwrap ¶
func (e CircularReferenceError) Unwrap() error
Unwrap returns the underlying error for errors.Is compatibility.
type DependencySorter ¶
type DependencySorter struct{}
DependencySorter handles topological sorting by dependencies.
func (DependencySorter) Sort ¶
func (ds DependencySorter) Sort(containers []types.Container) error
Sort sorts containers in place by dependencies, placing Watchtower containers last.
This function implements a two-phase sorting strategy to ensure proper update order:
- Separate Watchtower containers from regular containers, as Watchtower instances should always be updated last to avoid disrupting the update process itself.
- Perform topological sorting on non-Watchtower containers using Kahn's algorithm to respect dependency relationships (containers that depend on others must be updated after their dependencies).
The sorting ensures that: - Dependent containers are updated after their dependencies - Watchtower containers are processed last to maintain monitoring capability - Circular dependencies are detected and reported as errors
Time Complexity: O(V + E) where V is containers and E is dependency links Space Complexity: O(V + E) for graph structures
Parameters:
- containers: Slice to sort in place. Modified directly.
Returns:
- error: Non-nil if circular reference detected, nil on success. Error includes the container name and cycle path for debugging.
type IdentifierCollisionError ¶
type IdentifierCollisionError struct {
DuplicateIdentifier string
AffectedContainers []types.Container
}
IdentifierCollisionError represents an error when multiple containers have the same normalized identifier.
func (IdentifierCollisionError) Error ¶
func (e IdentifierCollisionError) Error() string
Error implements the error interface.
func (IdentifierCollisionError) Unwrap ¶
func (e IdentifierCollisionError) Unwrap() error
Unwrap returns the underlying error for errors.Is compatibility.