Skip to content

Add registerControllerWithoutLeaderElection for per-replica controllers#4193

Merged
kcp-ci-bot merged 1 commit into
mainfrom
refactor/register-controller-without-leader-election
Jun 5, 2026
Merged

Add registerControllerWithoutLeaderElection for per-replica controllers#4193
kcp-ci-bot merged 1 commit into
mainfrom
refactor/register-controller-without-leader-election

Conversation

@mjudeikis
Copy link
Copy Markdown
Contributor

Summary

Controllers that only maintain per-process, in-memory state which a replica's own API server depends on (and never write to storage) must run on every replica, not just the elected leader. Previously the only such case — the DynamicRESTMapper builtin/dynamic controllers — was wired through a bespoke post-start hook guarded by a sync.Once.

Generalize that into the controller framework: add a controllersWithoutLeaderElection registry with registerControllerWithoutLeaderElection(), started once per process from the kcp-start-controllers post-start hook via startControllersWithoutLeaderElection(), independent of the leader-election machinery. This mirrors registerController()/ startControllers() for the leader-elected set.

Convert the DynamicRESTMapper controllers to register through it, removing the one-off hook and the sync.Once/cached-error fields. installDynamicRESTMapper is idempotent (installControllers can run again on leadership re-acquisition): it returns early if the controllers are already registered, so their informer event handlers are not added twice.

No functional change: the DynamicRESTMapper controllers still run on every replica exactly once.

What Type of PR Is This?

/kind chore

Related Issue(s)

Fixes #

Release Notes

Refactor controller registration pattern for non-leader-election controllers

Controllers that only maintain per-process, in-memory state which a replica's own API
server depends on (and never write to storage) must run on every replica, not just the
elected leader. Previously the only such case — the DynamicRESTMapper builtin/dynamic
controllers — was wired through a bespoke post-start hook guarded by a sync.Once.

Generalize that into the controller framework: add a controllersWithoutLeaderElection
registry with registerControllerWithoutLeaderElection(), started once per process from the
kcp-start-controllers post-start hook via startControllersWithoutLeaderElection(),
independent of the leader-election machinery. This mirrors registerController()/
startControllers() for the leader-elected set.

Convert the DynamicRESTMapper controllers to register through it, removing the one-off hook
and the sync.Once/cached-error fields. installDynamicRESTMapper is idempotent (installControllers
can run again on leadership re-acquisition): it returns early if the controllers are already
registered, so their informer event handlers are not added twice.

No functional change: the DynamicRESTMapper controllers still run on every replica exactly once.
@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/chore Categorizes issue or PR as related to maintenance and other usually non-code changes. dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 5, 2026
Copy link
Copy Markdown
Member

@ntnn ntnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 5, 2026
@kcp-ci-bot
Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 772910cc0b30bcfc4186bc02c089d17fef707a38

@kcp-ci-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ntnn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 5, 2026
@kcp-ci-bot kcp-ci-bot merged commit 0de5713 into main Jun 5, 2026
14 checks passed
@kcp-ci-bot kcp-ci-bot deleted the refactor/register-controller-without-leader-election branch June 5, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/chore Categorizes issue or PR as related to maintenance and other usually non-code changes. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants