forked from tomkiin/mosquitto-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1.22 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
package main
import (
"os"
mqttv1 "github.com/tomkiin/mosquitto-operator/api/v1"
"github.com/tomkiin/mosquitto-operator/controller"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
var scheme = runtime.NewScheme()
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(mqttv1.AddToScheme(scheme))
}
func main() {
ctrl.SetLogger(zap.New(func(o *zap.Options) {
o.Development = true
o.TimeEncoder = zapcore.TimeEncoderOfLayout("2006/01/02 15:04:05")
}))
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: "0",
})
if err != nil {
ctrl.Log.Error(err, "Create Manager failed")
os.Exit(1)
}
controller := &controller.MosquittoReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}
if err := controller.Setup(mgr); err != nil {
ctrl.Log.Error(err, "Start Controller failed")
os.Exit(1)
}
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
ctrl.Log.Error(err, "Start Manager failed")
os.Exit(1)
}
}