postgres-operator/pkg/controller
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
..
controller.go Fix deletion timestamp handling for clusters with finalizers 2025-12-14 20:29:01 +01:00
logs_and_api.go deprecate ClusterName field of Postgresql type and remove team from REST endpoints (#2015) 2022-08-29 15:00:25 +02:00
node.go End 2 End tests speedup (#1180) 2020-10-28 10:04:33 +01:00
node_test.go diff SecurityContext of containers (#1255) 2020-12-15 10:06:53 +01:00
operator_config.go bump to v1.15.0 (#2965) 2025-10-21 11:56:33 +02:00
pod.go Move operator to go 1.14 (#882) 2020-03-30 15:50:17 +02:00
postgresql.go Improve sync responsiveness with background execution and context cancellation 2025-12-14 20:43:53 +00:00
postgresql_test.go allow delete only if annotations meet configured criteria (#1069) 2020-08-13 16:36:22 +02:00
types.go Bootstrapped databases with best practice role setup (#843) 2020-04-29 10:56:06 +02:00
util.go upgrade Go from 1.23.4 to 1.25.0 (#2945) 2025-08-19 14:40:39 +02:00
util_test.go reflect linter feedback, remove unused argumnents and redundant type from arrays (#2739) 2024-08-27 17:56:07 +02:00