Refactor libvirt event handling + reconcile when domains change#41
Merged
PhilippMatthes merged 8 commits intomainfrom Jan 13, 2026
Merged
Refactor libvirt event handling + reconcile when domains change#41PhilippMatthes merged 8 commits intomainfrom
PhilippMatthes merged 8 commits intomainfrom
Conversation
6a647bd to
7d886e3
Compare
61d380a to
04e1c00
Compare
mchristianl
reviewed
Jan 12, 2026
Contributor
mchristianl
left a comment
There was a problem hiding this comment.
I've marked
- a data race on shared libvirt connection
- race condition on event handler map
- reconnect is logged but not (yet) implemented?
- busy loop in runEventLoop
- maybe unbuffered channels are not intended here
Again, I think that concurrency and shared access are a bit spread over different locations in the source code. Therefore I would suggest to test this in a simpler setting first but let's discuss this.
Also, as we've already discussed I don't trust the libvirt socket and
- currently we won't get lifecycle events on migration (the qemu driver has implemented them) so pure event-based state tracking is blocked by this feature
- at least restarting the libvirt socket should be supported (but I may be mistaken to just have overlooked the logic if present)
2a49401 to
e649f93
Compare
Member
Author
|
^ Added a goroutine which triggers a reconcile every minute. |
Merging this branch changes the coverage (1 decrease, 2 increase)
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
mchristianl
approved these changes
Jan 13, 2026
SoWieMarkus
approved these changes
Jan 13, 2026
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.
With this change, we now reconcile the hypervisor resource if any libvirt domain lifecycle events occur. This keeps the hypervisor allocation up to date and simplifies how we manage the domain list.
We can only subscribe to libvirt events once. This means, we have to pull out the subscription logic from the
runMigrationListenerfunction inlibvirt_events.go. We provide a newWatchDomainChangesinterface function which can be used to subscribe to libvirt events, and reuse it for the existing migration watching and lifecycle logging. Furthermore, the distribution of libvirt events to the listeners is handled by a new event loop. Then, we also separate the logic unrelated to "migration watching" out, improving the overall structure and clarity of the code.Finally, we make the hypervisor controller reconcile as soon as we obtain a new domain lifecycle event. This is done with the proper mechanism provided by the controller-runtime client library: raw channel sources. The libvirt event subscription is wired together with the controller-runtime event channel on startup of the manager.