postgres-operator/pkg
Thomas Rosenstein 0affa9425a Improve sync responsiveness with background execution and context cancellation
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
2025-12-14 20:43:53 +00:00
..
apis update codegen (#2832) 2025-01-03 16:18:17 +01:00
apiserver Add operator deployment readiness probe (#1874) 2023-01-05 18:29:47 +01:00
cluster Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
controller Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
generated update codegen (#2832) 2025-01-03 16:18:17 +01:00
spec skip db user actions when its secret failed to sync on update (#2969) 2025-11-05 16:28:37 +01:00
teams improve additional teams lookup (#2445) 2023-10-16 16:48:19 +02:00
util Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00