Skip to content

Decouple conversion webhook registration from leader election#678

Open
sergenyalcin wants to merge 1 commit into
crossplane:mainfrom
sergenyalcin:register-webhooks-seperately
Open

Decouple conversion webhook registration from leader election#678
sergenyalcin wants to merge 1 commit into
crossplane:mainfrom
sergenyalcin:register-webhooks-seperately

Conversation

@sergenyalcin

@sergenyalcin sergenyalcin commented Jun 17, 2026

Copy link
Copy Markdown
Member

Description of your changes

Conversion webhook registration was accidentally gated behind leader election through the SetupGated/gate mechanism. SetupGated stores a closure that only fires on the elected leader, so follower pods never called ctrl.NewWebhookManagedBy and their webhook servers returned 404 for every conversion request. With two replicas and --leader-election, some conversion webhook calls fail.

The fix separates webhook registration from reconciler setup:

  • controller.go.tmpl: adds SetupWebhookWithManager — a standalone function that registers the conversion webhook for a single resource kind. Removes the if o.StartWebhooks { ... } block from Setup; webhook registration is no longer the reconciler's responsibility.

  • setup.go.tmpl: adds the SetupWebhookWithManager{{ .Group }} aggregator, following the same pattern as Setup{{ .Group }} and SetupGated{{ .Group }}, so providers can register all webhooks for a group in a single call.

Providers call SetupWebhookWithManager_<group> once before mgr.Start() on every pod, independent of the gate and leader election. Reconciler setup remains behind the gate and runs only on the leader.

See the generated provider with these changes: crossplane-contrib/provider-upjet-gcp#953 and crossplane-contrib/provider-upjet-aws#2122

I have:

  • Read and followed Upjet's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Tested locally by sending webhook calls to the webhook handlers.

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
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