Skip to content

Commit 64ac44f

Browse files
committed
Allow startFunc to block
1 parent bf93966 commit 64ac44f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

providers/multi/provider.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func (p *Provider) splitClusterName(clusterName string) (string, string) {
9090
// The startFunc is called to start the provider - starting the provider
9191
// outside of startFunc is an error and will result in undefined
9292
// behaviour.
93-
// startFunc should not block.
94-
// If startFunc returns an error the provider is not added and the error
93+
// startFunc should block for as long as the provider is running,
94+
// If startFunc returns an error the provider is removed and the error
9595
// is returned.
9696
func (p *Provider) AddProvider(ctx context.Context, prefix string, provider multicluster.Provider, startFunc func(context.Context, mctrl.Manager) error) error {
9797
ctx, cancel := context.WithCancel(ctx)
@@ -113,16 +113,20 @@ func (p *Provider) AddProvider(ctx context.Context, prefix string, provider mult
113113
sep: p.opts.Separator,
114114
}
115115
}
116-
if err := startFunc(ctx, wrappedMgr); err != nil {
117-
cancel()
118-
return fmt.Errorf("failed to start provider %q: %w", prefix, err)
119-
}
120116

121117
p.providerLock.Lock()
122118
p.providers[prefix] = provider
123119
p.providerCancel[prefix] = cancel
124120
p.providerLock.Unlock()
125121

122+
go func() {
123+
defer p.RemoveProvider(prefix)
124+
if err := startFunc(ctx, wrappedMgr); err != nil {
125+
cancel()
126+
p.log.Error(err, "error in provider", "prefix", prefix)
127+
}
128+
}()
129+
126130
return nil
127131
}
128132

0 commit comments

Comments
 (0)