hive: Support supplying a custom Lifecycle via Options - #81
Merged
Merged
Conversation
NewWithOptions always constructs a cell.DefaultLifecycle, so an application embedding hive cannot swap in its own implementation even though cell.Lifecycle is an exported interface and DefaultLifecycle is exported precisely for applications with nested lifecycles. Wrapping the lifecycle is useful to run a hive inside an outer lifecycle, to instrument hooks or to build test harnesses around a hive. Add an optional Lifecycle field to Options. When set, the hive provides it to the cells and drives Start and Stop through it. When nil, a DefaultLifecycle is created with the configured LogThreshold as before, so existing users are unaffected. Fixes: cilium#39 Signed-off-by: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com>
KR-Ravindra
force-pushed
the
feature/custom-lifecycle-option
branch
from
September 13, 2026 06:17
3bb0a22 to
130ca59
Compare
KR-Ravindra
marked this pull request as ready for review
September 19, 2026 23:06
joamaki
approved these changes
Sep 22, 2026
derailed
approved these changes
Sep 23, 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.
Problem
hive.NewWithOptionsalways constructs acell.DefaultLifecycle, so an application embedding hive cannot supply its owncell.Lifecycle(nested lifecycles, hook instrumentation, test harnesses) even thoughcell.Lifecycleis an exported interface andDefaultLifecycleis exported for that purpose.Root cause
hive.go:135(NewWithOptions) hard-codeslifecycle: &cell.DefaultLifecycle{LogThreshold: opts.LogThreshold}andOptionshas no way to override it.Fix
Add an optional
Lifecycle cell.Lifecyclefield tohive.Options, as proposed in the issue. When set, the hive provides it to the cells and drivesStart/Stopthrough it; when nil, aDefaultLifecyclewith the configuredLogThresholdis created as before, so existing callers are unaffected.cell.Modulealready passes non-DefaultLifecycleimplementations through unchanged.How tested
Added
TestCustomLifecycle(a wrapper embedding*cell.DefaultLifecyclethat countsAppend/Start/Stop, passed viaopts.Lifecycle, asserting it is the lifecycle injected into cells and that each counter is 1 afterh.Start/h.Stop) andTestDefaultLifecycle(nilopts.Lifecyclestill yields a*cell.DefaultLifecyclecarryingopts.LogThreshold).Before the fix:
After the fix:
go build ./...,go vet ./...,gofmt -l .andgo test ./...(plus-raceon the root package) pass.Links
This change was prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it.