Skip to content

Commit

Permalink
Merge pull request #102 from facchettos/startasync
Browse files Browse the repository at this point in the history
added startAsync
  • Loading branch information
FabianKramm authored Jul 1, 2024
2 parents 41f6d72 + 99189d3 commit 5e4d3e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions plugin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ type Manager interface {
// will stop if the pod will lose leader election.
Start() error

// 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
// the given object.
UnmarshalConfig(into interface{}) error
Expand Down

0 comments on commit 5e4d3e2

Please sign in to comment.