|
2 | 2 | // for registry resources in the ToolHive Registry Server. |
3 | 3 | // |
4 | 4 | // This package implements a clean separation of concerns by extracting all |
5 | | -// sync-related logic from the controller into dedicated interfaces: |
| 5 | +// sync-related logic from the controller into dedicated interfaces and types: |
| 6 | +// |
| 7 | +// # Core Interfaces |
6 | 8 | // |
7 | 9 | // - Manager: Main interface for orchestrating sync operations |
8 | 10 | // - DataChangeDetector: Detects changes in source data using hash comparison |
9 | 11 | // - AutomaticSyncChecker: Manages time-based automatic sync scheduling |
10 | 12 | // |
11 | | -// The package follows Go best practices by using interfaces for testability |
12 | | -// and dependency injection, while providing concrete struct implementations |
13 | | -// for actual functionality. |
| 13 | +// # Result Types |
| 14 | +// |
| 15 | +// - Result: Contains the outcome of successful sync operations (hash, server count) |
| 16 | +// - Error: Structured error type with Kubernetes condition information |
| 17 | +// |
| 18 | +// # Sync Decision Making |
| 19 | +// |
| 20 | +// The Manager.ShouldSync method evaluates multiple factors to determine if a sync |
| 21 | +// is needed, returning a decision (bool), reason (string), and next sync time: |
| 22 | +// |
| 23 | +// - Registry state (failed, not ready, complete) |
| 24 | +// - Filter configuration changes (via hash comparison) |
| 25 | +// - Source data changes (via hash comparison) |
| 26 | +// - Manual sync requests (via annotations) |
| 27 | +// - Automatic sync intervals (time-based policies) |
| 28 | +// - Requeue timing (minimum time between sync attempts) |
| 29 | +// |
| 30 | +// # Sync Reasons |
| 31 | +// |
| 32 | +// The package defines extensive reason constants to track why syncs occur or don't: |
| 33 | +// |
| 34 | +// - ReasonAlreadyInProgress: Sync already running |
| 35 | +// - ReasonRegistryNotReady: Initial sync or recovery from failure |
| 36 | +// - ReasonSourceDataChanged: Source data hash changed |
| 37 | +// - ReasonFilterChanged: Filter configuration modified |
| 38 | +// - ReasonManualWithChanges: Manual sync requested with detected changes |
| 39 | +// - ReasonManualNoChanges: Manual sync requested but no changes detected |
| 40 | +// - ReasonUpToDateWithPolicy: No sync needed, automatic policy active |
| 41 | +// - ReasonUpToDateNoPolicy: No sync needed, no automatic policy |
| 42 | +// - ReasonRequeueTimeNotElapsed: Too soon to retry after last attempt |
| 43 | +// - ReasonErrorCheckingChanges: Error during change detection |
| 44 | +// |
| 45 | +// # Kubernetes Status Integration |
| 46 | +// |
| 47 | +// The package defines condition types for Kubernetes status reporting: |
| 48 | +// |
| 49 | +// - ConditionSourceAvailable: Source is accessible |
| 50 | +// - ConditionDataValid: Registry data passes validation |
| 51 | +// - ConditionSyncSuccessful: Last sync operation succeeded |
| 52 | +// - ConditionAPIReady: Registry API is ready to serve requests |
| 53 | +// |
| 54 | +// The Error type includes condition information for automatic status updates: |
| 55 | +// - ConditionType: Which condition to update |
| 56 | +// - ConditionReason: Reason code for the condition |
| 57 | +// - Message: Human-readable error message |
| 58 | +// |
| 59 | +// # Timing Configuration |
| 60 | +// |
| 61 | +// Default timing constants control sync behavior: |
| 62 | +// |
| 63 | +// - DefaultSyncRequeueAfter: Minimum time between sync attempts (5 minutes) |
| 64 | +// This variable can be modified in tests for faster iteration |
| 65 | +// |
| 66 | +// # Key Features |
14 | 67 | // |
15 | | -// Key features: |
16 | 68 | // - Hash-based change detection to avoid unnecessary syncs |
17 | | -// - Manual sync support via annotations |
| 69 | +// - Filter change detection via hash comparison |
| 70 | +// - Manual sync support via Kubernetes annotations |
18 | 71 | // - Automatic sync scheduling with configurable intervals |
19 | | -// - Comprehensive error handling and status management |
| 72 | +// - Comprehensive error handling with structured Error types |
| 73 | +// - Detailed sync reason tracking for observability |
20 | 74 | // - Clean integration with Kubernetes controller patterns |
| 75 | +// - Resource cleanup on Registry deletion |
| 76 | +// |
| 77 | +// # Implementation |
| 78 | +// |
| 79 | +// The package follows Go best practices by using interfaces for testability |
| 80 | +// and dependency injection, while providing concrete struct implementations |
| 81 | +// (DefaultSyncManager, DefaultDataChangeDetector, DefaultAutomaticSyncChecker) |
| 82 | +// for actual functionality. |
21 | 83 | package sync |
0 commit comments