forked from goharbor/harbor-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
98 lines (77 loc) · 2.42 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"os"
"github.com/go-logr/logr"
"github.com/ovh/configstore"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
goharborv1alpha1 "github.com/goharbor/harbor-operator/api/v1alpha1"
"github.com/goharbor/harbor-operator/pkg/controllers/harbor"
"github.com/goharbor/harbor-operator/pkg/factories/logger"
"github.com/goharbor/harbor-operator/pkg/manager"
"github.com/goharbor/harbor-operator/pkg/scheme"
"github.com/goharbor/harbor-operator/pkg/tracing"
)
const (
OperatorName = "harbor-operator"
OperatorVersion = "devel"
)
const (
exitCodeFailure = 1
)
func getLogger() logr.Logger {
development, err := configstore.Filter().GetItemValueBool("dev-mode")
if err != nil {
development = true
}
return zap.Logger(development)
}
func main() {
// uses env var CONFIGURATION_FROM=... to initialize config
// examples of possible values:
// CONFIGURATION_FROM=file:/etc/cfg1.conf,file:/etc/cfg2.conf
// CONFIGURATION_FROM=env
// ...
configstore.InitFromEnvironment()
setupLog := ctrl.Log.WithName("setup")
ctx := logger.Context(setupLog)
logger := getLogger()
ctrl.SetLogger(logger)
scheme, err := scheme.New(ctx)
if err != nil {
setupLog.Error(err, "unable to create scheme")
os.Exit(exitCodeFailure)
}
mgr, err := manager.New(ctx, scheme)
if err != nil {
setupLog.Error(err, "unable to create manager")
os.Exit(exitCodeFailure)
}
traCon, err := tracing.New(ctx, OperatorName, OperatorVersion)
if err != nil {
setupLog.Error(err, "unable to create tracer")
os.Exit(exitCodeFailure)
}
defer traCon.Close()
reconciler, err := harbor.New(ctx, OperatorName, OperatorVersion)
if err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Harbor")
os.Exit(exitCodeFailure)
}
if err := reconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to setup controller", "controller", "Harbor")
os.Exit(exitCodeFailure)
}
if err := (&goharborv1alpha1.Harbor{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Harbor")
os.Exit(exitCodeFailure)
}
// +kubebuilder:scaffold:builder
setupLog.Info("starting manager", "version", OperatorVersion)
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "cannot start manager")
os.Exit(exitCodeFailure)
}
}