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
- type ArchiveResult
- type CleanupResult
- type DiskMonitor
- type NixGCResult
- type Service
- func (s *Service) ArchiveDeployments(ctx context.Context) (*ArchiveResult, error)
- func (s *Service) CleanupAttic(ctx context.Context) (*CleanupResult, error)
- func (s *Service) CleanupContainers(ctx context.Context) (*CleanupResult, error)
- func (s *Service) CleanupImages(ctx context.Context) (*CleanupResult, error)
- func (s *Service) GetSettings() *Settings
- func (s *Service) LoadSettings(ctx context.Context) error
- func (s *Service) SaveSettings(ctx context.Context, settings *Settings) error
- func (s *Service) TriggerNixGC(ctx context.Context, nodeID string) (*NixGCResult, error)
- type Settings
Constants ¶
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.
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.
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 ¶
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 ¶
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 ¶
GetSettings returns the current cleanup settings. Returns nil if settings have not been loaded.
func (*Service) LoadSettings ¶
LoadSettings loads cleanup settings from the store, applying defaults if not configured. **Validates: Requirements 15.1, 15.3, 15.4**
func (*Service) SaveSettings ¶
SaveSettings validates and saves cleanup settings to the store. Returns an error if validation fails. **Validates: Requirements 15.2**
func (*Service) TriggerNixGC ¶
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.