planner

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetServiceNames

func GetServiceNames(services []ServiceInfo) []string

GetServiceNames extracts service names from a list of ServiceInfo.

func NeedsApply

func NeedsApply(services []ServiceInfo) bool

NeedsApply determines if any services in the list require application/reconciliation.

Types

type DockerClient

type DockerClient interface {
	// Volume operations
	ListVolumes(ctx context.Context) ([]string, error)
	CreateVolume(ctx context.Context, name string, labels map[string]string) error
	RemoveVolume(ctx context.Context, name string) error

	// Volume file operations
	ReadFileFromVolume(ctx context.Context, volumeName, targetPath, relFile string) (string, error)
	WriteFileToVolume(ctx context.Context, volumeName, targetPath, relFile, content string) error
	ExtractTarToVolume(ctx context.Context, volumeName, targetPath string, tarReader io.Reader) error
	RemovePathsFromVolume(ctx context.Context, volumeName, targetPath string, relPaths []string) error

	// Network operations
	ListNetworks(ctx context.Context) ([]string, error)
	CreateNetwork(ctx context.Context, name string, labels map[string]string) error
	RemoveNetwork(ctx context.Context, name string) error

	// Container operations
	ListComposeContainersAll(ctx context.Context) ([]dockercli.PsBrief, error)
	RestartContainer(ctx context.Context, name string) error
	RemoveContainer(ctx context.Context, name string, force bool) error
	UpdateContainerLabels(ctx context.Context, containerName string, labels map[string]string) error
	InspectContainerLabels(ctx context.Context, containerName string, keys []string) (map[string]string, error)

	// Compose operations
	ComposeConfigFull(ctx context.Context, root string, files []string, profiles []string, envFiles []string, inline []string) (dockercli.ComposeConfigDoc, error)
	ComposeConfigServices(ctx context.Context, root string, files []string, profiles []string, envFiles []string, inline []string) ([]string, error)
	ComposeConfigHash(ctx context.Context, root string, files []string, profiles []string, envFiles []string, project, serviceName, identifier string, inline []string) (string, error)
	ComposePs(ctx context.Context, root string, files []string, profiles []string, envFiles []string, project string, inline []string) ([]dockercli.ComposePsItem, error)
	ComposeUp(ctx context.Context, root string, files []string, profiles []string, envFiles []string, project string, inline []string) (string, error)
}

DockerClient defines the interface for Docker operations needed by the planner. This allows for easy mocking in tests and potential future support for other container runtimes.

type FilesetManager

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

FilesetManager handles synchronization of filesets into Docker volumes.

func NewFilesetManager

func NewFilesetManager(planner *Planner) *FilesetManager

NewFilesetManager creates a new fileset manager.

func (*FilesetManager) SyncFilesets

func (fm *FilesetManager) SyncFilesets(ctx context.Context, cfg manifest.Config, existingVolumes map[string]struct{}) (map[string]struct{}, error)

SyncFilesets synchronizes all filesets into their target volumes and returns services that need restart.

type Plan

type Plan struct {
	Lines []ui.DiffLine
}

Plan represents a set of diff lines to show to the user.

func (*Plan) String

func (pln *Plan) String() string

type Planner

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

Planner creates a plan comparing desired and current docker state.

func New

func New() *Planner

func NewWithDocker

func NewWithDocker(client DockerClient) *Planner

func (*Planner) Apply

func (p *Planner) Apply(ctx context.Context, cfg manifest.Config) error

Apply creates missing top-level resources with labels and performs compose up, labeling containers with identifier.

func (*Planner) BuildPlan

func (p *Planner) BuildPlan(ctx context.Context, cfg manifest.Config) (*Plan, error)

BuildPlan currently produces a minimal plan for top-level volumes and networks. Future: inspect docker for current state and diff services/apps.

func (*Planner) Prune

func (p *Planner) Prune(ctx context.Context, cfg manifest.Config) error

Prune removes unmanaged resources labeled with the identifier. It deletes volumes, networks, and containers that are labeled but not present in cfg.

func (*Planner) WithParallel

func (p *Planner) WithParallel(enabled bool) *Planner

WithParallel enables or disables parallel processing for plan building.

func (*Planner) WithPrinter

func (p *Planner) WithPrinter(pr ui.Printer) *Planner

WithPrinter sets the output printer for user-facing messages during apply/prune.

func (*Planner) WithProgress

func (p *Planner) WithProgress(pb *ui.Progress) *Planner

WithProgress sets a progress bar to report stepwise progress during apply.

type ProgressEstimator

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

ProgressEstimator handles estimation of total work items for progress tracking.

func NewProgressEstimator

func NewProgressEstimator(planner *Planner) *ProgressEstimator

NewProgressEstimator creates a new progress estimator.

func (*ProgressEstimator) EstimateAndStartProgress

func (pe *ProgressEstimator) EstimateAndStartProgress(ctx context.Context, cfg manifest.Config, identifier string) error

EstimateAndStartProgress calculates the total number of work items and starts the progress tracker.

type ResourceManager

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

ResourceManager handles creation of top-level resources like volumes and networks.

func NewResourceManager

func NewResourceManager(planner *Planner) *ResourceManager

NewResourceManager creates a new resource manager.

func (*ResourceManager) EnsureNetworksExist

func (rm *ResourceManager) EnsureNetworksExist(ctx context.Context, cfg manifest.Config, labels map[string]string) error

EnsureNetworksExist creates any missing networks defined in the manifest.

func (*ResourceManager) EnsureVolumesExist

func (rm *ResourceManager) EnsureVolumesExist(ctx context.Context, cfg manifest.Config, labels map[string]string) (map[string]struct{}, error)

EnsureVolumesExist creates any missing volumes derived from filesets and explicit volume definitions.

type RestartManager

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

RestartManager handles restarting services after fileset updates.

func NewRestartManager

func NewRestartManager(planner *Planner) *RestartManager

NewRestartManager creates a new restart manager.

func (*RestartManager) RestartPendingServices

func (rm *RestartManager) RestartPendingServices(ctx context.Context, restartPending map[string]struct{}) error

RestartPendingServices restarts all services queued for restart after fileset updates.

type ServiceInfo

type ServiceInfo struct {
	Name        string
	AppName     string
	State       ServiceState
	DesiredHash string
	RunningHash string
	Container   *dockercli.ComposePsItem // nil if not running
}

ServiceInfo contains information about a service's desired and actual state.

type ServiceState

type ServiceState int

ServiceState represents the current state of a service relative to its desired configuration.

const (
	// ServiceMissing indicates the service is not running
	ServiceMissing ServiceState = iota
	// ServiceRunning indicates the service is running and up-to-date
	ServiceRunning
	// ServiceDrifted indicates the service is running but configuration has drifted
	ServiceDrifted
	// ServiceIdentifierMismatch indicates the service is running but has wrong identifier label
	ServiceIdentifierMismatch
)

type ServiceStateDetector

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

ServiceStateDetector handles detection of service state changes.

func NewServiceStateDetector

func NewServiceStateDetector(docker DockerClient) *ServiceStateDetector

NewServiceStateDetector creates a new service state detector.

func (*ServiceStateDetector) BuildInlineEnv

func (d *ServiceStateDetector) BuildInlineEnv(ctx context.Context, app manifest.Application, sopsConfig *manifest.SopsConfig) []string

BuildInlineEnv constructs the inline environment variables for an application, including SOPS secrets.

func (*ServiceStateDetector) DetectAllServicesState

func (d *ServiceStateDetector) DetectAllServicesState(ctx context.Context, appName string, app manifest.Application, identifier string, sopsConfig *manifest.SopsConfig) ([]ServiceInfo, error)

DetectAllServicesState analyzes the state of all services in an application.

func (*ServiceStateDetector) DetectServiceState

func (d *ServiceStateDetector) DetectServiceState(ctx context.Context, serviceName, appName string, app manifest.Application, identifier string, inline []string, running map[string]dockercli.ComposePsItem) (ServiceInfo, error)

DetectServiceState determines the state of a single service.

func (*ServiceStateDetector) GetPlannedServices

func (d *ServiceStateDetector) GetPlannedServices(ctx context.Context, app manifest.Application, inline []string) ([]string, error)

GetPlannedServices returns the list of services defined in the application's compose files.

func (*ServiceStateDetector) GetRunningServices

func (d *ServiceStateDetector) GetRunningServices(ctx context.Context, app manifest.Application, inline []string) (map[string]dockercli.ComposePsItem, error)

GetRunningServices returns a map of currently running services for the application.

func (*ServiceStateDetector) WithParallel

func (d *ServiceStateDetector) WithParallel(enabled bool) *ServiceStateDetector

WithParallel enables or disables parallel processing for service state detection.

Jump to

Keyboard shortcuts

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