This change improves the responsiveness of the operator when handling deletion requests by running sync operations in the background and using context cancellation to interrupt stuck operations. Changes: - Add context field to Cluster struct, passed through New() - Add Cancel() method to cancel cluster's context - Add StartSync/EndSync/NeedsResync for managing background sync state - Run Sync() in a background goroutine so worker can process other events - Add context-aware DB connection methods (initDbConnWithContext) - Add RetryWithContext() that respects context cancellation - Cancel cluster context immediately when DeletionTimestamp detected - Use context-aware connections in syncRoles/syncDatabases - StartSync/NeedsResync check context cancellation to prevent new syncs during deletion (no need for separate deleted flag) Flow: 1. Sync event spawns background goroutine and returns immediately 2. If another sync arrives while one is running, needsResync flag is set 3. When sync completes, it checks needsResync and requeues if needed 4. Delete cancels context -> stuck DB operations return early -> mutex released 5. StartSync/NeedsResync return false when context cancelled 6. Delete proceeds without waiting for slow/stuck sync operations |
||
|---|---|---|
| .. | ||
| apis | ||
| apiserver | ||
| cluster | ||
| controller | ||
| generated | ||
| spec | ||
| teams | ||
| util | ||