From 907b2c05b816e3dcc8affb66e828a848e5b74ea5 Mon Sep 17 00:00:00 2001 From: Jeremy Facchetti Date: Fri, 28 Jun 2024 16:18:30 +0200 Subject: [PATCH 1/2] added startAsync --- plugin/manager.go | 9 +++++++++ plugin/plugin.go | 4 ++++ plugin/types.go | 5 +++++ 3 files changed, 18 insertions(+) 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 From 99189d3f51d8db582a256badabc58202c628a153 Mon Sep 17 00:00:00 2001 From: Jeremy Facchetti Date: Fri, 28 Jun 2024 16:22:35 +0200 Subject: [PATCH 2/2] updated comment --- plugin/types.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/types.go b/plugin/types.go index 1413ffe3..01644a19 100644 --- a/plugin/types.go +++ b/plugin/types.go @@ -37,9 +37,10 @@ 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. + // Start runs all the registered syncers and will not block. It only executes + // the functionality if the current vcluster pod is the current leader + // You need to exit the plugin when the channel is closed since that means you lost + // leader election StartAsync() (<-chan struct{}, error) // UnmarshalConfig retrieves the plugin config from environment and parses it into