cleanup

package
v0.0.12 Latest Latest
Warning

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

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

Documentation

Overview

Package cleanup provides services for automatic cleanup and disk monitoring.

Package cleanup provides services for automatic cleanup of containers, images, Nix store paths, and deployment records.

Index

Constants

View Source
const (
	// DiskWarningThreshold is the percentage at which a warning is logged.
	// **Validates: Requirements 20.2**
	DiskWarningThreshold = 80.0

	// DiskCriticalThreshold is the percentage at which automatic cleanup is triggered.
	// **Validates: Requirements 20.3**
	DiskCriticalThreshold = 90.0
)

DiskUsageThresholds defines the thresholds for disk usage warnings and actions.

View Source
const (
	SettingContainerRetention  = "cleanup_container_retention"
	SettingImageRetention      = "cleanup_image_retention"
	SettingNixGCInterval       = "cleanup_nix_gc_interval"
	SettingDeploymentRetention = "cleanup_deployment_retention"
	SettingMinDeploymentsKept  = "cleanup_min_deployments_kept"
	SettingAtticRetention      = "cleanup_attic_retention"
)

Settings keys for cleanup configuration.

View Source
const (
	DefaultContainerRetention  = 24 * time.Hour      // 1 day
	DefaultImageRetention      = 7 * 24 * time.Hour  // 7 days
	DefaultNixGCInterval       = 24 * time.Hour      // 1 day
	DefaultDeploymentRetention = 30 * 24 * time.Hour // 30 days
	DefaultMinDeploymentsKept  = 5
	DefaultAtticRetention      = 30 * 24 * time.Hour // 30 days
)

Default values for cleanup settings.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchiveResult

type ArchiveResult struct {
	DeploymentsArchived int           `json:"deployments_archived"`
	BuildsArchived      int           `json:"builds_archived"`
	LogsArchived        int           `json:"logs_archived"`
	Duration            time.Duration `json:"duration"`
	Errors              []string      `json:"errors,omitempty"`
}

ArchiveResult holds the result of a deployment archival operation.

type CleanupResult

type CleanupResult struct {
	ItemsRemoved int           `json:"items_removed"`
	SpaceFreed   int64         `json:"space_freed_bytes"`
	Errors       []string      `json:"errors,omitempty"`
	Duration     time.Duration `json:"duration"`
}

CleanupResult holds the result of a cleanup operation.

type DiskMonitor

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

DiskMonitor monitors disk usage on nodes and triggers warnings/cleanup.

func NewDiskMonitor

func NewDiskMonitor(st store.Store, cleanupSvc *Service, logger *slog.Logger) *DiskMonitor

NewDiskMonitor creates a new disk monitor.

func (*DiskMonitor) CheckAllNodes

func (m *DiskMonitor) CheckAllNodes(ctx context.Context) error

CheckAllNodes checks disk usage for all nodes and logs warnings. **Validates: Requirements 20.2, 20.3**

func (*DiskMonitor) CheckDiskUsage

func (m *DiskMonitor) CheckDiskUsage(ctx context.Context, nodeID string, diskMetrics *models.NodeDiskMetrics) bool

CheckDiskUsage checks disk usage for a node and logs warnings if thresholds are exceeded. Returns true if cleanup was triggered due to critical threshold. **Validates: Requirements 20.2, 20.3**

type NixGCResult

type NixGCResult struct {
	SpaceFreed   int64         `json:"space_freed_bytes"`
	PathsRemoved int           `json:"paths_removed"`
	Duration     time.Duration `json:"duration"`
	Error        string        `json:"error,omitempty"`
}

NixGCResult holds the result of a Nix garbage collection operation.

type Service

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

Service manages automatic cleanup of containers, images, and Nix store paths.

func NewService

func NewService(store store.Store, podman *podman.Client, logger *slog.Logger) *Service

NewService creates a new cleanup service.

func (*Service) ArchiveDeployments

func (s *Service) ArchiveDeployments(ctx context.Context) (*ArchiveResult, error)

ArchiveDeployments archives deployment records older than the configured retention period. Preserves the minimum N deployments per service regardless of age. Also archives associated build and log records. **Validates: Requirements 18.1, 18.2, 18.4**

func (*Service) CleanupAttic

func (s *Service) CleanupAttic(ctx context.Context) (*CleanupResult, error)

CleanupAttic triggers Attic binary cache cleanup. **Validates: Requirements 26.1, 26.2, 26.3, 26.4**

func (*Service) CleanupContainers

func (s *Service) CleanupContainers(ctx context.Context) (*CleanupResult, error)

CleanupContainers removes stopped containers older than the configured retention period. **Validates: Requirements 16.1, 16.2, 16.3**

func (*Service) CleanupImages

func (s *Service) CleanupImages(ctx context.Context) (*CleanupResult, error)

CleanupImages removes unused images older than the configured retention period. Images referenced by active deployments are preserved. **Validates: Requirements 25.1, 25.2**

func (*Service) GetSettings

func (s *Service) GetSettings() *Settings

GetSettings returns the current cleanup settings. Returns nil if settings have not been loaded.

func (*Service) LoadSettings

func (s *Service) LoadSettings(ctx context.Context) error

LoadSettings loads cleanup settings from the store, applying defaults if not configured. **Validates: Requirements 15.1, 15.3, 15.4**

func (*Service) SaveSettings

func (s *Service) SaveSettings(ctx context.Context, settings *Settings) error

SaveSettings validates and saves cleanup settings to the store. Returns an error if validation fails. **Validates: Requirements 15.2**

func (*Service) TriggerNixGC

func (s *Service) TriggerNixGC(ctx context.Context, nodeID string) (*NixGCResult, error)

TriggerNixGC triggers Nix garbage collection on a node. Active store paths referenced by running deployments are preserved via GC roots. **Validates: Requirements 17.1, 17.2**

type Settings

type Settings struct {
	ContainerRetention  time.Duration `json:"container_retention"`
	ImageRetention      time.Duration `json:"image_retention"`
	NixGCInterval       time.Duration `json:"nix_gc_interval"`
	DeploymentRetention time.Duration `json:"deployment_retention"`
	MinDeploymentsKept  int           `json:"min_deployments_kept"`
	AtticRetention      time.Duration `json:"attic_retention"`
}

Settings holds cleanup configuration loaded from the settings store.

func (*Settings) Validate

func (s *Settings) Validate() error

Validate validates that all cleanup settings have positive values. Returns an error if any retention period is non-positive. **Validates: Requirements 15.2**

Jump to

Keyboard shortcuts

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