Skip to content

chore: migrate status controller to events.EventRecorder API#205

Closed
jamesmt-aws wants to merge 1 commit intoawslabs:mainfrom
jamesmt-aws:chore/migrate-events-recorder
Closed

chore: migrate status controller to events.EventRecorder API#205
jamesmt-aws wants to merge 1 commit intoawslabs:mainfrom
jamesmt-aws:chore/migrate-events-recorder

Conversation

@jamesmt-aws
Copy link
Copy Markdown
Contributor

@jamesmt-aws jamesmt-aws commented Apr 9, 2026

Summary

  • Migrate status.NewController and status.NewGenericObjectController to take k8s.io/client-go/tools/events.EventRecorder instead of the deprecated k8s.io/client-go/tools/record.EventRecorder.
  • Translate the three internal eventRecorder.Event(...) call sites to Eventf(...) with action strings Finalize and TransitionCondition.
  • Tests use events.FakeRecorder, which emits the same <type> <reason> <note> channel format as the old fake — no assertion changes needed.

Motivation

controller-runtime v0.23 deprecated manager.GetEventRecorderFor and the legacy record.EventRecorder API in favor of the newer events.EventRecorder (k8s.io/client-go/tools/events). The deprecation notice says the old API will be removed in a future release.

Downstream consumers of operatorpkg cannot migrate off GetEventRecorderFor as long as status.NewController requires the legacy record.EventRecorder. In kubernetes-sigs/karpenter#2951 we currently have to add //nolint:staticcheck directives at every call site to suppress the SA1019 warning, which papers over the deprecation rather than addressing it.

This PR unblocks karpenter (and any other downstream consumer) to fully migrate to the new events API.

Breaking change

This changes the public signature of:

  • status.NewController[T Object](client, eventRecorder events.EventRecorder, ...)
  • status.NewGenericObjectController[T client.Object](client, eventRecorder events.EventRecorder, ...)

Callers will get a compile-time error with a clear migration path: replace mgr.GetEventRecorderFor(name) with mgr.GetEventRecorder(name). There is no silent behavior change.

I'm open to the parallel-constructor approach (NewControllerWithEventsRecorder alongside the existing one) if you'd prefer a softer migration — happy to rework if so.

Test plan

  • go test ./... passes locally
  • No test assertion changes required (FakeRecorder format is identical)
  • CI green

The legacy k8s.io/client-go/tools/record.EventRecorder API is deprecated
in controller-runtime v0.23 and slated for removal. Migrate the status
controller's recorder field, NewController/NewGenericObjectController
constructors, and tests to k8s.io/client-go/tools/events.EventRecorder.

Event call sites translate Event(...) to Eventf(..., nil, type, reason,
action, note, args...). Action strings are "Finalize" and
"TransitionCondition". The new events.FakeRecorder produces the same
"<type> <reason> <note>" channel format as the old record.FakeRecorder,
so existing test assertions continue to pass unchanged.
@jamesmt-aws jamesmt-aws requested a review from a team as a code owner April 9, 2026 16:45
jamesmt-aws added a commit to jamesmt-aws/karpenter that referenced this pull request Apr 9, 2026
Migrate pkg/events.NewRecorder to wrap k8s.io/client-go/tools/events.EventRecorder
instead of the deprecated k8s.io/client-go/tools/record.EventRecorder.

The new EventRecorder interface has a single Eventf method with both 'reason'
and 'action' parameters. Karpenter's Event abstraction only models a single
concept, and every existing Reason already describes the action the controller
took (e.g. EvictPod, DisruptionLaunching), so we reuse Reason as the action.
We pass nil for 'related' since karpenter events only ever describe a single
object.

Switch operator.go to mgr.GetEventRecorder, dropping one staticcheck nolint
introduced in kubernetes-sigs#2951. The three call sites in pkg/controllers/controllers.go
that pass the recorder directly to operatorpkg's status.NewController still
need their nolints until awslabs/operatorpkg#205 merges and we can bump.

Test fakes (InternalRecorder, &record.FakeRecorder{} usages across six test
suites) updated to the new interface. The new events.FakeRecorder produces
the same channel format as the old one.
@jamesmt-aws
Copy link
Copy Markdown
Contributor Author

Closing in favor of #206 for design discussion. The downstream urgency dropped — kubernetes-sigs/karpenter#2951 turned out to be cleanly shippable with the two existing nolints, and the deprecation isn't a removal yet. The branch (https://github.com/jamesmt-aws/operatorpkg/tree/chore/migrate-events-recorder) is parked and ready to reopen as a PR once the approach is settled in #206.

@jamesmt-aws jamesmt-aws closed this Apr 9, 2026
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