fix(overlord): allow ensure when state is available #482
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.
Managers can explicitly call
state.EnsureBefore()
if they wish to apply changes sooner than the scheduled 5min ensure overlord timer.Although managers get a state instance at creation time, during
overlord.New()
, it is currently forbidden to call ensure early on before theDaemon
started theoverlord.Loop()
. The current restriction stems from the fact thatstate.EnsureBefore()
adjusts the ensure timer expiry time, and the timer is only created whenoverlord.Loop()
is called.The problem:
Since the overlord ensure loop is only started later on during
daemon.Start()
, a manager has no direct way to know when it's safe to call Ensure. Managers currently have to use the first call to theirEnsure()
method as an indication the overlord loop was entered, which is unnecessary manager boilerplate code. Seeoverlord/checkstate/manager.go
.Managers (and managers with dependencies on other managers), may want to implement state changes during callbacks. These events can come from outside the overlord framework (e.g. from the Linux kernel or early on during manager
StartUp
), meaning that handlers using state may be triggered asynchronously from the Daemon startup sequence, and arrive before the overlord Loop is started.Solution:
Allow
state.EnsureBefore()
to be called before the timer exists. Since an implicit ensure is performed on overlord loop entry, simply returning while the timer does not exist is the same as saying an ensure is already scheduled.