forked from openshift/cluster-api-provider-libvirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
99 lines (82 loc) · 2.62 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
package main
import (
"github.com/openshift/cluster-api-provider-libvirt/pkg/apis"
"github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1alpha1"
machineactuator "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine"
libvirtclient "github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/client"
"github.com/openshift/cluster-api-provider-libvirt/pkg/controller"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
clusterapis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"flag"
"github.com/golang/glog"
"k8s.io/klog"
)
func main() {
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
flag.Parse()
flag.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
f2.Value.Set(value)
}
})
// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
glog.Fatal(err)
}
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
glog.Fatal(err)
}
glog.Infof("Registering Components.")
// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
glog.Fatal(err)
}
if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil {
glog.Fatal(err)
}
initActuator(mgr)
// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
glog.Fatal(err)
}
glog.Infof("Starting the Cmd.")
// Start the Cmd
glog.Fatal(mgr.Start(signals.SetupSignalHandler()))
}
func initActuator(m manager.Manager) {
config := m.GetConfig()
client, err := clientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Could not create client for talking to the apiserver: %v", err)
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatalf("Could not create kubernetes client to talk to the apiserver: %v", err)
}
codec, err := v1alpha1.NewCodec()
if err != nil {
glog.Fatal(err)
}
params := machineactuator.ActuatorParams{
ClusterClient: client,
KubeClient: kubeClient,
ClientBuilder: libvirtclient.NewClient,
Codec: codec,
EventRecorder: m.GetRecorder("libvirt-controller"),
}
machineactuator.MachineActuator, err = machineactuator.NewActuator(params)
if err != nil {
glog.Fatalf("Could not create Libvirt machine actuator: %v", err)
}
}