Skip to content

feat(operator)!: add scoped leader election#1192

Merged
kimpenhaus merged 7 commits into
mainfrom
feature/scoped-leader-election-type
Jul 11, 2026
Merged

feat(operator)!: add scoped leader election#1192
kimpenhaus merged 7 commits into
mainfrom
feature/scoped-leader-election-type

Conversation

@kimpenhaus

@kimpenhaus kimpenhaus commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds scoped leader election for partitioning entity responsibility across operator instances while retaining the standard watcher, queue, selector, and reconciliation pipeline.

Also adds field-selector support to Kubernetes client list and synchronous watch operations.

Breaking changes

  • IKubernetesClient.List, ListAsync, and Watch now accept fieldSelector after labelSelector.
  • Typed selector overloads now accept KubernetesSelector[] instead of LabelSelector[].
  • Positional calls passing a cancellation token must use the updated parameter order or name the argument explicitly.

- Introduced `LeaderElectionType.Scoped` for namespace-partitioned leadership.
- Added `ScopeAwareResourceWatcher` and `ScopeAwareEntityQueueBackgroundService` to enhance multi-instance responsibility handling.
- Implemented `ILeadershipScope` for user-defined namespace responsibility coordination.
- Updated tests and registration validation for scoped leader election.
- Revised documentation for `LeaderElectionType.Scoped`, including setup and behavior details.
…ope handling

- Replaced `LeadershipScopeChange` with `NamespacedLeadershipScope` for better abstraction and to enable partitioning by Kubernetes namespaces.
- Updated `ILeadershipScope` to handle entity-based responsibility instead of namespaces.
- Refactored scope-aware components to align with the new abstraction.
- Adjusted tests for `ScopeAwareEntityQueueBackgroundService`, `ScopeAwareResourceWatcher`, and related entities to use the new structure.
- Removed redundant namespace-focused logic for cleaner and more flexible resync mechanisms.
…nce leadership scope handling

- Introduced `ShouldReconcileAsync` to allow entity-based reconciliation veto decisions.
- Updated `ScopeAwareEntityQueueBackgroundService` to base leadership responsibility on current entity state.
- Added tests to validate scoped reconciliation decisions for added, modified, and deleted entities.
- Enhanced test coverage with `ScopeAwareSharedResourceWatcher`.
- Optimized `ScopeAwareEntityQueueBackgroundService` by removing redundant responsibility checks.
…methods

- Extended `List`, `ListAsync`, and `Watch` methods to accept field selectors.
- Updated label and field selector handling with `KubernetesSelector` for better filtering capabilities.
- Adjusted positional overloads to align with Kubernetes client parameter conventions.
- Revised test coverage to validate new selector functionality.
- Updated migration documentation with required changes for v13 compatibility.
… unchanged generation

- Fixed regression where reacquired entities with unchanged generation were skipped during scope resync.
- Dropped deduplication tokens for entity types on scope change to force reconciliation for all in-scope entities.
- Updated `ScopeAwareResourceWatcher` with enhanced cache handling to prevent missed reconciliations.
- Added regression test to validate behavior during scope transitions.
@kimpenhaus kimpenhaus changed the title feat(operator): add scoped leader election feat(operator)!: add scoped leader election Jul 11, 2026
@kimpenhaus
kimpenhaus marked this pull request as ready for review July 11, 2026 22:23
…ions` utility

- Added `ToExpressions` extension method for splitting label and field selectors.
- Updated `List`, `ListAsync`, and `Watch` methods to use the new utility, improving readability and reducing duplication.
- Introduced unit tests for `ToExpressions` to validate selector transformation behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant