-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix: remove deprecated field of manager option #684
Conversation
411fab2
to
e028306
Compare
1b55d56
to
22be434
Compare
22be434
to
4629c09
Compare
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.
While the EventBroadcaster
field is deprecated because of potential leak/lock issue, the broadcaster is still currently used to create all the chaos-controller events (because it actually hosts the Recorder
).
This diagram in the Slack Notifier PR is still valid in that regard and might help visualise how the interfaces are setup.
The event Recorder
object we use to create all our events is extracted from the manager. The manager (behind the scenes) recorder
object is highly correlated to its broadcaster.
When we r.record()
an event, the event is actually sent the recorder of the broadcaster of the manager -- and the broadcaster in question has to be the one we customise with our notifier system and pass as an argument at manager creation. Otherwise I assume the NewManager
function creates a default one.
If we remove this line as it is we will simply remove the notifier (notifierSinks + filtering) system. I'll read the updated docs and investigate for the new correct way to implement this !
4629c09
to
feeac48
Compare
The broadcaster is an interface of the Go kubernetes client that allows you to create custom events from your controller, and send them to the kubernetes cluster. It also allows for custom event filtering, anti-spam filtering, and sink broadcasting (ie. send the event to any interface before/while sending it to the api server). When we looked for solutions to notify users of specific controller behaviours (eg. NoTargetFound warning event), leveraging the manager EventBroadcaster interface came up as the best, most effective and easy-to-implement solution. Since then, we have added 4-5 different sinks including slack and datadog, and heavily rely on setting up our own Broadcaster interface to create our events and send them to various sinks. In order to set up our custom EventBroadcaster, we have to create it and give it to the manager at setup, as shown in the code above.
The EventBroadcaster is used to send custom events but is also used by the controller for LeaderElection. This is a process where multiple instances of the controller on one cluster could coordinate through events and share load. In 2020, open source maintainers reacted to an issue describing goroutine leaks related to the EventBroadcaster lifecycle. To ensure correct deletion of the EventBroadcaster with the controller deletion it needs to be instantiated after the manager. A patch PR strongly reduced the possibility for leaks by lazy loading the broadcaster and marked the field as deprecated. The broadcaster is only instantiated when an event is actually emitted – and that’s expected to be done by the LeaderElection process. We do not emit events before calling
This is a stable issue that has not caused us issues as far as we know. Reading the patch PR description, as we declare our own custom broadcaster, we should call a I did not find a better way to implement our event and notification system within the provided stack, but stay open to possibilities. While we will monitor for goroutine leaks in the future, this works reliably and seems under control. |
Thank @nathantournant for this clear explanation! 👍 For now, we can keep this field and add the |
feeac48
to
d9dfca9
Compare
I might be totally misunderstanding, but is the fact that we pass this to the manager even relevant? We pass it separately to the At least superficially, I would expect everything to keep working if we removed |
90bbcb0
to
265f1bc
Compare
This is a valid take; the EventBroadcaster does have the ability to generate an EventRecorder, that we can then use in the DisruptionReconciler. It will then be standalone. Concerns are;
Latest commit includes a proposal/PoC that splits the two broadcasters, and makes the custom broadcaster send events to kubernetes. If the resource consumption is not absurd (which is likely), we can clean it up and use that instead. |
good to know. We almost always run w/ leader election off, but i wouldn't want to change how that behavior works without consideratioh
Ahh, I didn't realize that. Great point, thanks! |
@@ -42,6 +43,10 @@ func RegisterNotifierSinks(mgr ctrl.Manager, broadcaster record.EventBroadcaster | |||
broadcaster.StartRecordingToSink(&NotifierSink{client: client, notifier: notifier, logger: logger}) | |||
} | |||
|
|||
corev1Client, _ := corev1client.NewForConfig(mgr.GetConfig()) |
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.
This part of code can be removed if we don't need to send event to kubernetes.
Datadog ReportBranch report: ✅ |
What should we do with this pull request? Should I close it and continue using the deprecated method, or should we switch to the new method? @nathantournant @ptnapoleon |
I think it's up to you? You'd be the one doing the change, it doesn't seem urgent, but it is always healthy to move away from deprecated components |
15a8f56
to
f9f13d8
Compare
Datadog ReportBranch report: ✅ |
f9f13d8
to
5ec250c
Compare
5ec250c
to
54dabf7
Compare
Datadog ReportBranch report: ✅ |
The EventBroadcaster field of ctrl.Options{} has indeed been deprecated since controller-runtime v0.8.0, and it has been replaced by the Recorder interface.
0716282
to
a2d9fe7
Compare
Datadog ReportBranch report: ✅ |
What does this PR do?
Please briefly describe your changes as well as the motivation behind them:
EventBroadcaster
field of ctrl.Options{} has indeed been deprecated since controller-runtime v0.8.0, and it has been replaced by the Recorder interface. It will be removed in the future release. To avoid issues I prefered to removed it to don't be impacted.Code Quality Checklist
Testing
unit
tests orend-to-end
tests.unit
tests orend-to-end
tests.