-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (41 loc) · 1.21 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
package main
import (
"golanglearning/new_project/crd_practice/pkg/controller"
"golanglearning/new_project/crd_practice/pkg/k8sconfig"
"golanglearning/new_project/crd_practice/pkg/type_object"
"os"
"sigs.k8s.io/controller-runtime/pkg/builder"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)
func main() {
logf.SetLogger(zap.New())
var logs = logf.Log.WithName("crdpractice")
// 1. 初始化manager
mgr, err := manager.New(k8sconfig.K8sRestConfig(), manager.Options{})
if err != nil {
logs.Error(err, "unable to set up manager")
os.Exit(1)
}
// 2. 管理器加入scheme
err = k8sconfig.SchemeBuilder.AddToScheme(mgr.GetScheme())
if err != nil {
logs.Error(err, "unable add schema")
os.Exit(1)
}
// 3. 控制器
err = builder.ControllerManagedBy(mgr).
For(&type_object.Tester{}).
Complete(controller.NewCrdPracticeController())
if err != nil {
logs.Error(err, "unable to create manager")
os.Exit(1)
}
// 4. 管理器启动
if err = mgr.Start(signals.SetupSignalHandler()); err != nil {
logs.Error(err, "unable to start manager")
os.Exit(1)
}
}