Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStaleAgentDuration ¶ added in v4.4.0
GetStaleAgentDuration returns the configured duration for stale agent cleanup. Defaults to 24 hours if not configured.
func NewKubernetesCleanupFunc ¶ added in v4.1.0
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 ¶ added in v4.1.0
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 ¶ added in v4.1.0
type KubernetesCleanupStats struct {
ServicesFound int
ServicesDeleted int
PVCsFound int
PVCsDeleted int
SecretsFound int
SecretsDeleted int
}
KubernetesCleanupStats tracks statistics about the cleanup operation.
type LockService ¶ added in v4.1.0
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
// 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
}
Service defines the interface for database maintenance operations.
func NewService ¶
NewService creates a new maintenance service with only a store.