mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-20 09:49:11 +00:00
bug: Make bus Initialize idempotent, add Reload
This commit is contained in:
committed by
Itxaka
parent
1254c09745
commit
6b5c4d416c
@@ -68,7 +68,7 @@ func Run(opts ...Option) error {
|
||||
}
|
||||
|
||||
// Re-load providers
|
||||
bus.Manager.LoadProviders()
|
||||
bus.Reload()
|
||||
err = machine.CreateSentinel("bundles")
|
||||
if !c.IgnoreBundleErrors && err != nil {
|
||||
return err
|
||||
|
@@ -10,14 +10,24 @@ import (
|
||||
)
|
||||
|
||||
// Manager is the bus instance manager, which subscribes plugins to events emitted.
|
||||
var Manager = &Bus{
|
||||
var Manager = NewBus()
|
||||
|
||||
func NewBus() *Bus {
|
||||
return &Bus{
|
||||
Manager: pluggable.NewManager(
|
||||
bus.AllEvents,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func Reload() {
|
||||
Manager = NewBus()
|
||||
Manager.Initialize()
|
||||
}
|
||||
|
||||
type Bus struct {
|
||||
*pluggable.Manager
|
||||
registered bool
|
||||
}
|
||||
|
||||
func (b *Bus) LoadProviders() {
|
||||
@@ -26,6 +36,7 @@ func (b *Bus) LoadProviders() {
|
||||
}
|
||||
|
||||
func (b *Bus) Initialize() {
|
||||
if !b.registered {
|
||||
b.LoadProviders()
|
||||
for i := range b.Manager.Events {
|
||||
e := b.Manager.Events[i]
|
||||
@@ -51,4 +62,6 @@ func (b *Bus) Initialize() {
|
||||
}
|
||||
})
|
||||
}
|
||||
b.registered = true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user