Skip to content

Fix #8994 (approach C): adopt controller-runtime TypedEventHandler - #9006

Closed
wallrj-cyberark wants to merge 1 commit into
cert-manager:masterfrom
wallrj-cyberark:8994-fix-c-typed-event-handler
Closed

wallrj-cyberark wants to merge 1 commit into
cert-manager:masterfrom
wallrj-cyberark:8994-fix-c-typed-event-handler

Conversation

@wallrj-cyberark

Copy link
Copy Markdown
Member

Summary

Adopt controller-runtime's handler.TypedEventHandler for cert-manager's
informer event handling, fixing #8994 and aligning with the upstream
pattern.

  • Replace blockingEventHandler[T] with handler.TypedFuncs[T, types.NamespacedName] from controller-runtime.
  • Change filteredEventHandler[T] to wrap
    handler.TypedEventHandler[T, types.NamespacedName] instead of
    cache.ResourceEventHandler. This moves all type assertions into the
    adapter layer (filteredEventHandler) and delivers fully typed events
    downstream — no type casts in work functions.
  • Split AddEventHandler into separate typed and metadata registration
    methods (same structural fix as approach B).
  • The issuer and clusterissuer controllers register on both informers;
    certificate sub-controllers register only on the typed informer.

This is a stepping stone toward full controller-runtime adoption. The
filteredEventHandler is the cert-manager equivalent of
controller-runtime's internal.EventHandler — it bridges client-go
informers to the typed handler interface.

See also:

All three PRs target master for review and CI; they are mutually
exclusive approaches to the same issue.

Motivation

#8994 — discovered shortly after the 1.21.0
release. The generics refactor in #8407 changed the handler signature
from func(interface{}) to func(U), which broke the dual-informer
Secret handler path.

Test plan

  • go test ./pkg/controller/ — TestBlockingEventHandler,
    TestQueuingEventHandler, TestFilterEventHandler,
    TestOnlyUpdateWhenResourceChanged all pass
  • go test ./pkg/controller/certificates/... — all pass
  • go test ./pkg/controller/issuers/... — pass
  • go test ./pkg/controller/clusterissuers/... — pass
  • go test ./internal/informers/... — pass

@cert-manager-prow

Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 10, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jakexks for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@cert-manager-prow cert-manager-prow Bot added the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Jul 10, 2026
@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 10, 2026
@wallrj-cyberark
wallrj-cyberark force-pushed the 8994-fix-c-typed-event-handler branch 2 times, most recently from 1cb7c63 to 481afef Compare July 10, 2026 15:50
Replace cert-manager's custom blockingEventHandler with controller-runtime's
handler.TypedFuncs, and change filteredEventHandler to wrap
handler.TypedEventHandler[T, types.NamespacedName] instead of
cache.ResourceEventHandler. This aligns cert-manager's event handler
architecture with controller-runtime's typed handler pattern, where the
adapter layer (filteredEventHandler) performs the sole type assertion and
all downstream handlers receive fully typed events.

Also split AddEventHandler into separate typed and metadata informer
registration methods, fixing the log spam described in cert-manager#8994 where a
handler typed as *corev1.Secret received *v1.PartialObjectMetadata from
the metadata informer. The issuer and clusterissuer controllers register
on both informers; certificate sub-controllers register only on the typed
informer.

Fixes: cert-manager#8994

Signed-off-by: Richard Wall <[email protected]>
Co-Authored-By: Claude <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

Closing this in favour of #9005.

Why: #8994 itself is already fixed on master via #9004 (merged, cherry-picked to release-1.21 as #9037), and the structural half of this PR — splitting AddEventHandler into typed/metadata-only registration — has been carried forward on its own in #9005, which is now updated with e2e log evidence and a release note. There's no need for two PRs carrying the same structural fix.

This PR's remaining, distinguishing value was the second half: adopting controller-runtime's handler.TypedEventHandler/handler.TypedFuncs in place of cert-manager's own blockingEventHandler. On reflection I don't think that half is ready to land as-is, independent of the structural fix:

  • It uses context.TODO() in three places rather than threading a real context through.
  • It passes nil for handler.TypedFuncs's workqueue.TypedRateLimitingInterface parameter — cert-manager's workFuncs close over their own queue and ignore it, so this adopts the interface's shape without its intended usage pattern (controller-runtime expects that parameter to be the enqueue mechanism).
  • It drops the diagnostic log.Error(...) that used to fire on a type-assertion mismatch, in favour of a silent return. Reasonable once Register Secret event handlers only on informers whose object type they handle #9005's split makes such mismatches structurally unreachable in normal operation, but it's an implicit assumption baked into silent code rather than a documented invariant.
  • It pulls in a transitive go.sum bump (gofuzz v1.2.0) that isn't otherwise explained by the diff.

None of these are hard blockers on their own, but together they read as "adopt the interface because it looks similar" rather than "adopt controller-runtime's actual reconciliation model", which is where I think the real value would come from.

Thoughts on incremental controller-runtime adoption, for whenever there's appetite to revisit this: hjoshi123 already flagged in review of #8255 that "when we do eventually move issuers" is an anticipated direction (#8255 (comment)), so there's at least informal awareness that this is coming. My suggestion would be to treat it as a deliberate, tracked migration rather than swapping individual internal adapters piecemeal:

  1. Pick one self-contained, low-consumer-count controller (e.g. clusterissuers, which has a single Secret dependency and no fan-out to other controllers) and migrate it end-to-end to controller-runtime's Manager/Controller/Reconciler pattern, including real context propagation and actual use of the provided workqueue — not just the event-handler adapter layer in isolation.
  2. Use that as the template to validate the idioms (context threading, error handling, requeue semantics) before rolling out further.
  3. Only then revisit filteredEventHandler/blockingEventHandler — at that point the surrounding controller code would actually be shaped to consume handler.TypedEventHandler as designed, rather than bridging an old client-go-style controller onto a controller-runtime-shaped adapter.

Happy to pick this up as a separate proposal once there's a decision on priority — for now, closing to avoid two structurally-overlapping PRs sitting open.

@wallrj-cyberark
wallrj-cyberark deleted the 8994-fix-c-typed-event-handler branch July 17, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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.

1 participant