Add informers and internal go routines in manager (#2870)

* used manager's Add function in more places
* exit when ctx.Done is received in archivePruner go routines
* fix manager tests
* fix data race
* added more gpm function in manager and removed manager from a util function
* closed unused channel and stopped ticker after context is done
* added log statements
* used context.Done inside function instead of stopper channel
This commit is contained in:
Vardhaman Surana
2023-11-10 12:42:21 +05:30
committed by GitHub
parent 2a40b4538c
commit 3fabf64b3c
28 changed files with 195 additions and 114 deletions
+20 -11
View File
@@ -74,7 +74,7 @@ type (
)
// MakeExecutor returns an Executor for given ExecutorType(s).
func MakeExecutor(ctx context.Context, logger *zap.Logger, cms *cms.ConfigSecretController,
func MakeExecutor(ctx context.Context, logger *zap.Logger, mgr manager.Interface, cms *cms.ConfigSecretController,
fissionClient versioned.Interface, types map[fv1.ExecutorType]executortype.ExecutorType,
informers ...k8sCache.SharedIndexInformer) (*Executor, error) {
executor := &Executor{
@@ -88,17 +88,21 @@ func MakeExecutor(ctx context.Context, logger *zap.Logger, cms *cms.ConfigSecret
// Run all informers
for _, informer := range informers {
go informer.Run(ctx.Done())
informer := informer
mgr.Add(ctx, func(ctx context.Context) {
informer.Run(ctx.Done())
})
}
for _, et := range types {
go func(et executortype.ExecutorType) {
et.Run(ctx)
}(et)
et := et
mgr.Add(ctx, func(ctx context.Context) {
et.Run(ctx, mgr)
})
}
go executor.serveCreateFuncServices()
mgr.Add(ctx, func(ctx context.Context) {
executor.serveCreateFuncServices(ctx)
})
return executor, nil
}
@@ -108,9 +112,14 @@ func MakeExecutor(ctx context.Context, logger *zap.Logger, cms *cms.ConfigSecret
// get specialized. In other words, it ensures that when there's an
// ongoing request for a certain function, all other requests wait for
// that request to complete.
func (executor *Executor) serveCreateFuncServices() {
func (executor *Executor) serveCreateFuncServices(ctx context.Context) {
for {
req := <-executor.requestChan
var req *createFuncServiceRequest
select {
case <-ctx.Done():
return
case req = <-executor.requestChan:
}
function := req.function
fnName := k8sCache.MetaObjectToName(function)
fnkeyUR := crd.CacheKeyURFromObject(function)
@@ -384,7 +393,7 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
informerFactory.Start(ctx.Done())
}
api, err := MakeExecutor(ctx, logger, cms, fissionClient, executorTypes,
api, err := MakeExecutor(ctx, logger, mgr, cms, fissionClient, executorTypes,
fissionInformers...,
)
if err != nil {