graph

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNodeNames

func GetNodeNames(nodes []*Node) []string

GetNodeNames extracts container names from a list of nodes

Types

type Builder

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

Builder constructs dependency graphs from container information

func NewBuilder

func NewBuilder(dockerClient DockerClient, logger *logger.Logger) *Builder

NewBuilder creates a new graph builder

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, containers []container.Summary) (*Graph, error)

Build creates a dependency graph from a list of containers

type ComponentBatches

type ComponentBatches struct {
	Batches [][]*Node // Batches of nodes that can run in parallel within this component
}

ComponentBatches represents a single connected component with its batches

type DockerClient

type DockerClient interface {
	GetContainer(ctx context.Context, containerID string) (*client.ContainerInspectResult, error)
}

DockerClient interface for container operations needed by the builder

type Graph

type Graph struct {
	Nodes map[string]*Node // Key is container name
}

Graph represents the complete dependency graph of containers

func (*Graph) GetConnectedComponents

func (g *Graph) GetConnectedComponents() ([]*ComponentBatches, error)

GetConnectedComponents identifies independent subgraphs in the dependency graph. Each component is a set of containers that are connected through dependencies (directly or indirectly). Containers in different components have no dependency relationships with each other and can be processed in parallel.

Returns a slice of components, where each component contains batches of nodes. Nodes within the same batch have no dependencies on each other and can run in parallel.

func (*Graph) GetConnectedComponentsForShutdown

func (g *Graph) GetConnectedComponentsForShutdown() ([]*ComponentBatches, error)

GetConnectedComponentsForShutdown returns components ordered for shutdown (same components but batches are reversed)

func (*Graph) GetLeafNodes

func (g *Graph) GetLeafNodes() []*Node

GetLeafNodes returns all nodes with no children

func (*Graph) GetNode

func (g *Graph) GetNode(name string) (*Node, bool)

GetNode retrieves a node by container name

func (*Graph) GetRootNodes

func (g *Graph) GetRootNodes() []*Node

GetRootNodes returns all nodes with no parent dependencies

func (*Graph) GetShutdownBatches

func (g *Graph) GetShutdownBatches() ([][]*Node, error)

GetShutdownBatches groups containers into batches for parallel shutdown This is the reverse of startup batches

func (*Graph) GetStartupBatches

func (g *Graph) GetStartupBatches() ([][]*Node, error)

GetStartupBatches groups containers into batches that can be started in parallel Containers in the same batch have no dependencies on each other

func (*Graph) HasCycles

func (g *Graph) HasCycles() (bool, []string)

HasCycles checks if the graph contains circular dependencies

func (*Graph) TopologicalSort

func (g *Graph) TopologicalSort() (*SortedContainers, error)

TopologicalSort performs a topological sort on the dependency graph Returns containers in startup order (dependencies first)

func (*Graph) Validate

func (g *Graph) Validate() error

Validate checks the graph for errors (cycles, invalid dependencies, etc.)

type Node

type Node struct {
	// Container information
	ID            string
	Name          string
	Labels        map[string]string
	IsRunning     bool
	IsPlaceholder bool // True if container doesn't exist but is referenced as a dependency

	// Dependency information
	Parents  []*Node // Containers this one depends on (must start first)
	Children []*Node // Containers that depend on this one (start after)

	// Startup configuration from labels
	StartupDelay       int  // Delay in seconds after dependencies are ready
	WaitForHealthcheck bool // Wait for health check to pass

	// Container configuration
	StopTimeout *int // Container's configured stop timeout in seconds (nil = Docker default of 10s)
	// contains filtered or unexported fields
}

Node represents a container in the dependency graph

func FilterByNames

func FilterByNames(nodes []*Node, excludeNames map[string]bool) []*Node

FilterByNames returns nodes filtered by a list of names to exclude

func FilterByState

func FilterByState(nodes []*Node, running bool) []*Node

FilterByState returns nodes filtered by running state

func NewNode

func NewNode(summary container.Summary) *Node

NewNode creates a new graph node from container information

func NewPlaceholderNode

func NewPlaceholderNode(name string) *Node

NewPlaceholderNode creates a placeholder node for a missing dependency

func (*Node) AddParent

func (n *Node) AddParent(parent *Node)

AddParent adds a parent dependency (this node depends on parent)

func (*Node) HasChildren

func (n *Node) HasChildren() bool

HasChildren returns true if the node has any child dependencies

func (*Node) HasParents

func (n *Node) HasParents() bool

HasParents returns true if the node has any parent dependencies

type SortedContainers

type SortedContainers struct {
	StartupOrder  []*Node // Order for starting containers
	ShutdownOrder []*Node // Order for stopping containers (reverse of startup)
}

SortedContainers represents the result of topological sort

Jump to

Keyboard shortcuts

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