Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStaleAgentDuration ¶
GetStaleAgentDuration returns the configured duration for stale agent cleanup. Defaults to 24 hours if not configured.
func NewKubernetesCleanupFunc ¶
func NewKubernetesCleanupFunc(config KubernetesCleanupConfig) func(ctx context.Context, dryRun bool) error
NewKubernetesCleanupFunc creates a function to clean up stale Kubernetes resources. It cleans up Services (crow-svc-*), PVCs (wp-*), and Secrets (wp-*, crow-*) that are older than the configured threshold.
Permission Requirements: - If config.Namespaces is specified, requires permissions in those namespaces only - If config.Namespaces is empty, only requires permissions in the current namespace - No cluster-wide permissions required (no ClusterRole needed)
This would allow more precise filtering and avoid potential false positives.
Types ¶
type KubernetesCleanupConfig ¶
type KubernetesCleanupConfig struct {
// ResourceAgeThreshold is the age threshold for resources to be considered stale
ResourceAgeThreshold time.Duration
// DryRun if true, will only log what would be deleted
DryRun bool
// Namespaces is the list of namespaces to clean up. If empty, uses current namespace
Namespaces []string
}
KubernetesCleanupConfig represents the configuration for Kubernetes cleanup.
type KubernetesCleanupStats ¶
type KubernetesCleanupStats struct {
ServicesFound int
ServicesDeleted int
PVCsFound int
PVCsDeleted int
SecretsFound int
SecretsDeleted int
}
KubernetesCleanupStats tracks statistics about the cleanup operation.
type LockService ¶
type LockService interface {
AcquireLock(ctx context.Context, lockName string, ttl time.Duration) (context.Context, context.CancelFunc, error)
}
LockService defines the interface for distributed locking.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages database maintenance scheduling.
func NewScheduler ¶
func NewScheduler(service Service, store store.Store, lockService LockService) *Scheduler
NewScheduler creates a new maintenance scheduler.
type Service ¶
type Service interface {
// RunMaintenance executes database maintenance operations
RunMaintenance(ctx context.Context) error
// RunKubernetesCleanup executes Kubernetes resource cleanup.
RunKubernetesCleanup(ctx context.Context, dryRun bool) error
// RunStaleAgentCleanup executes stale agent cleanup.
RunStaleAgentCleanup(ctx context.Context, staleDuration time.Duration) error
// RunOrphanedDataCleanup detects and cleans up DB rows that reference
// deleted forge users or repositories.
RunOrphanedDataCleanup(ctx context.Context, dryRun bool) error
// GetMaintenanceConfig returns the current maintenance configuration
GetMaintenanceConfig() *model.MaintenanceConfig
// UpdateMaintenanceConfig updates the maintenance configuration
UpdateMaintenanceConfig(config *model.MaintenanceConfig) error
// GetMaintenanceConfigByAction returns config for a specific action type
GetMaintenanceConfigByAction(actionType string) (*model.MaintenanceConfig, error)
// UpdateMaintenanceConfigByAction updates config for a specific action type
UpdateMaintenanceConfigByAction(actionType string, config *model.MaintenanceConfig) error
// IsKubernetesCleanupAvailable returns whether Kubernetes cleanup is available
IsKubernetesCleanupAvailable() bool
// GetMaintenanceStats returns maintenance statistics
GetMaintenanceStats() (*model.MaintenanceStats, error)
// SetKubernetesCleanupFunc sets the function to use for Kubernetes cleanup
SetKubernetesCleanupFunc(f func(ctx context.Context, dryRun bool) error)
// SetKubernetesCleanupEnabled sets whether Kubernetes cleanup is enabled for execution
SetKubernetesCleanupEnabled(enabled bool)
// SetVacuumEnvVarsConfigured sets whether vacuum-specific environment variables are overriding configuration
SetVacuumEnvVarsConfigured(vacuumEnvVarsSet bool)
// IsVacuumEnvVarsConfigured returns whether vacuum-specific environment variables are set
IsVacuumEnvVarsConfigured() bool
// SetKubernetesEnvVarsConfigured sets whether Kubernetes-specific environment variables are set
SetKubernetesEnvVarsConfigured(k8sEnvVarsSet bool)
// IsKubernetesEnvVarsConfigured returns whether Kubernetes-specific environment variables are set
IsKubernetesEnvVarsConfigured() bool
// SetOrphanedDataEnvVarsConfigured sets whether orphaned-data-cleanup-specific environment variables are set
SetOrphanedDataEnvVarsConfigured(orphanEnvVarsSet bool)
// IsOrphanedDataEnvVarsConfigured returns whether orphaned-data-cleanup-specific environment variables are set
IsOrphanedDataEnvVarsConfigured() bool
// SetStaleAgentEnvVarsConfigured sets whether stale-agent-cleanup-specific environment variables are set
SetStaleAgentEnvVarsConfigured(staleAgentEnvVarsSet bool)
// IsStaleAgentEnvVarsConfigured returns whether stale-agent-cleanup-specific environment variables are set
IsStaleAgentEnvVarsConfigured() bool
// IsDockerCleanupAvailable returns whether Docker cleanup is available
IsDockerCleanupAvailable() bool
// SetDockerCleanupAvailable sets whether Docker cleanup is available
SetDockerCleanupAvailable(available bool)
// GetDockerCleanupConfigForAgent returns Docker cleanup config to send to agents
GetDockerCleanupConfigForAgent() *rpc.DockerCleanupConfig
// RecordDockerCleanupResult records a Docker cleanup result from an agent
RecordDockerCleanupResult(agentID int64, agentName string, result rpc.DockerCleanupResult) error
// SetDockerCleanupRunNow triggers an immediate Docker cleanup
SetDockerCleanupRunNow()
}
Service defines the interface for database maintenance operations.
func NewService ¶
NewService creates a new maintenance service with only a store.