diff --git a/plugin/manager.go b/plugin/manager.go index b7988bc8..bc944f08 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -209,6 +209,15 @@ func (m *manager) Start() error { return nil } +func (m *manager) StartAsync() (<-chan struct{}, error) { + err := m.start() + if err != nil { + return nil, err + } + + return m.context.Context.Done(), nil +} + func (m *manager) startInterceptors() error { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handlerName := r.Header.Get("VCluster-Plugin-Handler-Name") diff --git a/plugin/plugin.go b/plugin/plugin.go index 22bfe576..4411bbd2 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -56,6 +56,10 @@ func Start() error { return defaultManager.Start() } +func StartAsync() (<-chan struct{}, error) { + return defaultManager.StartAsync() +} + func UnmarshalConfig(into interface{}) error { return defaultManager.UnmarshalConfig(into) } diff --git a/plugin/types.go b/plugin/types.go index 696ae96c..1413ffe3 100644 --- a/plugin/types.go +++ b/plugin/types.go @@ -37,6 +37,11 @@ type Manager interface { // will stop if the pod will lose leader election. Start() error + // Start runs all the registered syncers and will block. It only executes + // the functionality if the current vcluster pod is the current leader and + // will stop if the pod will lose leader election. + StartAsync() (<-chan struct{}, error) + // UnmarshalConfig retrieves the plugin config from environment and parses it into // the given object. UnmarshalConfig(into interface{}) error