-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharedmain.go
35 lines (29 loc) · 1.08 KB
/
sharedmain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package sharedmain
import (
"knative.dev/eventing/pkg/adapter/v2"
"knative.dev/pkg/injection"
"knative.dev/pkg/signals"
"github.com/zeiss/typhoon/pkg/routing/adapter/common/env"
)
type (
namedControllerConstructor func(component string) adapter.ControllerConstructor
namedAdapterConstructor func(component string) adapter.AdapterConstructor
)
// MainWithController is a shared main tailored to multi-tenant receive-adapters.
// It performs the following initializations:
// - process environment variables
// - enable leader election / HA
// - set the scope to a single namespace
// - inject the given controller constructor
func MainWithController(envCtor env.ConfigConstructor,
cCtor namedControllerConstructor, aCtor namedAdapterConstructor,
) {
envAcc := env.MustProcessConfig(envCtor)
ns := envAcc.GetNamespace()
component := envAcc.GetComponent()
ctx := signals.NewContext()
ctx = adapter.WithHAEnabled(ctx)
ctx = injection.WithNamespaceScope(ctx, ns)
ctx = adapter.WithController(ctx, cCtor(component))
adapter.MainWithEnv(ctx, component, envAcc, aCtor(component))
}