chore: migrate status controller to events.EventRecorder API#205
Closed
jamesmt-aws wants to merge 1 commit intoawslabs:mainfrom
Closed
chore: migrate status controller to events.EventRecorder API#205jamesmt-aws wants to merge 1 commit intoawslabs:mainfrom
jamesmt-aws wants to merge 1 commit intoawslabs:mainfrom
Conversation
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
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
status.NewControllerandstatus.NewGenericObjectControllerto takek8s.io/client-go/tools/events.EventRecorderinstead of the deprecatedk8s.io/client-go/tools/record.EventRecorder.eventRecorder.Event(...)call sites toEventf(...)with action stringsFinalizeandTransitionCondition.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.GetEventRecorderForand the legacyrecord.EventRecorderAPI in favor of the newerevents.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
GetEventRecorderForas long asstatus.NewControllerrequires the legacyrecord.EventRecorder. In kubernetes-sigs/karpenter#2951 we currently have to add//nolint:staticcheckdirectives 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)withmgr.GetEventRecorder(name). There is no silent behavior change.I'm open to the parallel-constructor approach (
NewControllerWithEventsRecorderalongside the existing one) if you'd prefer a softer migration — happy to rework if so.Test plan
go test ./...passes locally