-
Notifications
You must be signed in to change notification settings - Fork 113
/
main.go
107 lines (83 loc) · 2.25 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
99
100
101
102
103
104
105
106
107
package main
import (
"context"
"github.com/go-logr/logr"
"github.com/goharbor/harbor-operator/pkg/exit"
"github.com/goharbor/harbor-operator/pkg/factories/application"
"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/setup"
"github.com/goharbor/harbor-operator/pkg/tracing"
"github.com/ovh/configstore"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
)
var (
name = "harbor-operator"
version = "dev"
gitCommit = "none"
)
const (
LoggerExitCode int = iota + 1
ManagerExitCode
SchemeExitCode
TracingExitCode
ControllersExitCode
RunExitCode
)
func setupContextAndLogger() (context.Context, logr.Logger, error) {
setupLog := ctrl.Log.WithName("setup")
ctx := logger.Context(setupLog)
err := setup.Logger(ctx, name, version)
if err != nil {
return nil, ctrl.Log, err
}
application.SetName(&ctx, name)
application.SetVersion(&ctx, version)
application.SetGitCommit(&ctx, gitCommit)
return ctx, setupLog, nil
}
func main() {
defer exit.Exit()
ctx, setupLog, err := setupContextAndLogger()
if err != nil {
setupLog.Error(err, "unable to create logger")
exit.SetCode(LoggerExitCode)
return
}
configstore.InitFromEnvironment()
scheme, err := scheme.New(ctx)
if err != nil {
setupLog.Error(err, "unable to create scheme")
exit.SetCode(SchemeExitCode)
return
}
mgr, err := manager.New(ctx, scheme)
if err != nil {
setupLog.Error(err, "unable to create manager")
exit.SetCode(ManagerExitCode)
return
}
traCon, err := tracing.New(ctx)
if err != nil {
setupLog.Error(err, "unable to create tracer")
exit.SetCode(TracingExitCode)
return
}
defer traCon.Close()
if err := (setup.WithManager(ctx, mgr)); err != nil {
setupLog.Error(err, "unable to setup controllers")
exit.SetCode(ControllersExitCode)
return
}
// +kubebuilder:scaffold:builder
setupLog.Info("starting manager", "version", version, "commit", gitCommit)
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "cannot start manager")
if exit.GetCode() == exit.SuccessExitCode {
exit.SetCode(RunExitCode)
}
return
}
}