forked from knative/eventing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (64 loc) · 2.35 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"os"
istiov1alpha3 "github.com/knative/pkg/apis/istio/v1alpha3"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
provisionerController "github.com/knative/eventing/contrib/kafka/pkg/controller"
"github.com/knative/eventing/contrib/kafka/pkg/controller/channel"
eventingv1alpha "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
"github.com/knative/eventing/pkg/provisioners"
)
const (
BrokerConfigMapKey = "bootstrap_servers"
)
// SchemeFunc adds types to a Scheme.
type SchemeFunc func(*runtime.Scheme) error
// ProvideFunc adds a controller to a Manager.
type ProvideFunc func(mgr manager.Manager, config *provisionerController.KafkaProvisionerConfig, logger *zap.Logger) (controller.Controller, error)
func main() {
flag.Parse()
logf.SetLogger(logf.ZapLogger(false))
logger := provisioners.NewProvisionerLoggerFromConfig(provisioners.NewLoggingConfig())
defer logger.Sync()
// Setup a Manager
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{})
if err != nil {
logger.Error(err, "unable to run controller manager")
os.Exit(1)
}
// Add custom types to this array to get them into the manager's scheme.
schemeFuncs := []SchemeFunc{
eventingv1alpha.AddToScheme,
istiov1alpha3.AddToScheme,
}
for _, schemeFunc := range schemeFuncs {
schemeFunc(mgr.GetScheme())
}
// Add each controller's ProvideController func to this list to have the
// manager run it.
providers := []ProvideFunc{
provisionerController.ProvideController,
channel.ProvideController,
}
// TODO the underlying config map needs to be watched and the config should be reloaded if there is a change.
provisionerConfig, err := provisionerController.GetProvisionerConfig("/etc/config-provisioner")
if err != nil {
logger.Error(err, "unable to run controller manager")
os.Exit(1)
}
for _, provider := range providers {
if _, err := provider(mgr, provisionerConfig, logger.Desugar()); err != nil {
logger.Error(err, "unable to run controller manager")
os.Exit(1)
}
}
mgr.Start(signals.SetupSignalHandler())
}