-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
58 lines (46 loc) · 1.71 KB
/
controller.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package function
import (
"context"
"github.com/kelseyhightower/envconfig"
"knative.dev/eventing/pkg/reconciler/source"
k8sclient "knative.dev/pkg/client/injection/kube/client"
cminformerv1 "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"github.com/zeiss/typhoon/pkg/apis/extensions/v1alpha1"
informerv1alpha1 "github.com/zeiss/typhoon/pkg/client/generated/injection/informers/extensions/v1alpha1/function"
reconcilerv1alpha1 "github.com/zeiss/typhoon/pkg/client/generated/injection/reconciler/extensions/v1alpha1/function"
common "github.com/zeiss/typhoon/pkg/reconciler"
)
// NewController initializes the controller and is called by the generated code
// Registers event handlers to enqueue events
func NewController(
ctx context.Context,
cmw configmap.Watcher,
) *controller.Impl {
typ := (*v1alpha1.Function)(nil)
app := common.ComponentName(typ)
// Calling envconfig.Process() with a prefix appends that prefix
// (uppercased) to the Go field name, e.g. MYTARGET_IMAGE.
adapterCfg := &adapterConfig{
obsConfig: source.WatchConfigurations(ctx, app, cmw),
}
envconfig.MustProcess(app, adapterCfg)
informer := informerv1alpha1.Get(ctx)
r := &Reconciler{
adapterCfg: adapterCfg,
cmLister: cminformerv1.Get(ctx).Lister().ConfigMaps,
cmCli: k8sclient.Get(ctx).CoreV1().ConfigMaps,
}
impl := reconcilerv1alpha1.NewImpl(ctx, r)
r.base = common.NewGenericServiceReconciler[*v1alpha1.Function](
ctx,
typ.GetGroupVersionKind(),
impl.Tracker,
impl.EnqueueControllerOf,
informer.Lister().Functions,
)
informer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
r.tracker = impl.Tracker
return impl
}