-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠️ Migration to the new events API #3262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hi @clebs. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
Open Items:
|
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two questions
pkg/recorder/recorder.go
Outdated
GetEventRecorder(name string) events.EventRecorder | ||
// GetOldEventRecorder returns an EventRecorder for the old events API. | ||
// The old API is not 100% supported anymore, use the new one whenever possible. | ||
GetOldEventRecorder(name string) record.EventRecorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than extending the interface here, would it be possible to build a wrapper that makes a record.EventRecorder
out of a events.EventRecorder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is already built as a wrapper under the hood in intrec
. I added it here with the idea to support both APIs for some time. If it is not what we are going for, having the wrapper only where it is needed is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are two main ways we could go about this:
- We make this a non-breaking change by keeping the existing
GetEventRecorderFor
with the existing signature and add a newGetEventRecorder
with the newevents.EventRecorder
as return but mark theGetEventRecorderFor
as// deprecated
. At some point in a future release we will then removeGetEventRecorderFor
- We make this a breaking change by changing the signature of the existing
GetEventRecorderFor
to return anevents.EventRecorder
and we provide an adapter somewhere to go fromevents.EventRecorder
to arecord.EventRecorder
for places like the leader election
My vote if this is possible would be to do 1) as this is the least disruptive for c-r users but its possible I've missed something and it isn't possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 1 is doable, but I have to see if the wrapper approach is good enough. Reason being, that the wrapper calls the new API under the hood and both APIs are quite different. The old API has AnnotatedEventf
while the new one does not and the new one has things like relatedObject
and action
.
Otherwise, the other way to support both is having 2 distinct implementations in separate packages and duplicate the broadcaster, provider, interfaces and injection at the manager and cluster levels.
Finally also duplicate the tests so both versions are covered.
I will test if the wrapper is viable, present the results and then we can make an informed decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested out the wrapper and it has the one downside: we loose the ability to set annotations on events since there is no equivalent AnnotatedEventf
. I also have tried to get some info on why that is the case.
Seeing that, the wrapper can not provide the same features as the old API has, so the only option to support both is probably having both implementations at the same time.
@alvaroaleman my proposal is to duplicate the internal events package and have both implementations separate from each other even if that means lots of duplication for some time. It will make it easier later on to cleanup the old API when removed. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alvaroaleman my proposal is to duplicate the internal events package and have both implementations separate from each other even if that means lots of duplication for some time. It will make it easier later on to cleanup the old API when removed. What do you think?
Not great, but given its for a limited time only that seems okay to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also not a great fan.
I will do the exercise and see how much I can reuse without having a tangled nightmare.
Worst case it is all duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alvaroaleman I have gone through this and now this PR supports both the old and new events APIs with as little duplication as possible.
There is still a fair amount of duplication but it is confined mostly to internal code and should still be relatively easy to cleanup later on.
If you agree with this approach I will move to adding tests for the new API and move this out of draft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you agree with this approach I will move to adding tests for the new API and move this out of draft.
Sounds good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added and moved out of draft. PTAL!
Still finishing up the recorder integration test for the new API, but the code should be ready for review.
6bfbd83
to
0528c33
Compare
/assign |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: clebs The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -128,7 +128,7 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op | |||
coordinationClient, | |||
resourcelock.ResourceLockConfig{ | |||
Identity: id, | |||
EventRecorder: recorderProvider.GetEventRecorderFor(id), | |||
EventRecorder: recorderProvider.GetEventRecorderFor(id), //nolint:staticcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the plan to resolve this one?
Improve the upstream package so it can handle the new recorder, then use it here?
(if yes, let's make sure we have corresponding follow-up issues in CR & k/k)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this would require client-go
to migrate to the new API too. I will make sure to create followups once this is in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thx!
@clebs Just a heads up. If we want to get this into the next CR minor release the deadline is in 2-3 weeks. We want to release the next CR minor shortly after the Kubernetes minor which is scheduled for 27th August |
@sbueringer that should be doable. I will work in your remarks today. Maybe you have a suggestion there: controller-runtime/pkg/internal/recorder/recorder_integration_test.go Lines 118 to 127 in 95e07d9
|
Very quick first look. The error seems to be in another test:
|
I'm wondering if the client we are using in this test case is using the clientTransport for which we are force closing idle connections here: controller-runtime/pkg/manager/manager_test.go Line 1947 in bc36d51
(I think it should, but maybe it's somehow not) |
/retest I think one of the two failed test cases is an unrelated flake |
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
The StartEventWatcher call is no longer needed since calling StartRecordingToSink already sets up a watcher and manages it via its context. Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
- Remove outdated comment - Improve error handling when setting default Options - Replace deprecated sink recording function - log errors from StartEventWatcher Signed-off-by: Borja Clemente <[email protected]>
/retest |
Signed-off-by: Borja Clemente <[email protected]>
/retest |
@clebs: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
I have worked in all the feedback, thanks! I will try to figure out what is wrong with the tests. This new test is definitely affecting other suites somehow. |
This Pull Request migrates from the old events API (
k8s.io/client-go/tools/record
) to the new API (k8s.io/client-go/tools/events
).Closes #2141