-
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!
Looks like it's still occuring (at least the linter caching issue is "fixed" now) |
@sbueringer I indeed have to correct my previous statement saying it consistently succeeds. It does succeed when running I will look into this and try to get it fixed on CI. It seems the current state makes the tests timeout in different places. |
/retest (last one was an unrelated flake) |
/test pull-controller-runtime-test (Not sure if it should be already fixed or not :)) |
I have not made any changes since my last comment where I just rebased. I ran So I have been unable to pin this down and am not sure anymore whether it is still related to this PR. |
Last time I checked I didn't see flakes like this on main in testgrid. Also didn't notice on other PRs. Maybe the changes here make the flake more likely Edit: https://storage.googleapis.com/k8s-triage/index.html?pr=1&text=found%20unexpected%20goroutines&job=.*controller-runtime.* (4 occurences, all on this PR) Not sure if I'm searching for the right failure message |
Thanks for the infos @sbueringer ! It has helped me focus on this one issue and I found the leaking goroutine I think (on my potato laptop I get lots of noise from other failures when testing thus hard to confirm 100%). TLDR; I was ignoring the stopFunc returned by |
Very nice that the test found an actual issue :) /test pull-controller-runtime-test (I'm going to run the test a few more times just for more data) |
Damn :/ I'm starting to lean towards intentionally not merging this into the current minor release, even if the tests are fine a few times in a row eventually, because I would prefer data from testgrid over a longer period to ensure we're not introducing an issue |
Agreed, this needs more effort. I am not able to properly work on this with my current laptop. I will resume testing when I have access to modern hardware in a few days. |
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
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 <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
- Remove outdated comment - Improve error handling when setting default Options - Replace deprecated sink recording function - log errors from StartEventWatcher Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
Signed-off-by: Borja Clemente <borja.clemente@gmail.com>
4f82545
to
9a5f2a6
Compare
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