/
main.go
72 lines (57 loc) · 1.84 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
package main
import (
"flag"
"os"
lighthousev1alpha1 "github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
"github.com/jenkins-x/lighthouse/pkg/clients"
"github.com/jenkins-x/lighthouse/pkg/foghorn"
"github.com/jenkins-x/lighthouse/pkg/logrusutil"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
)
type options struct {
namespace string
}
func (o *options) Validate() error {
return nil
}
func gatherOptions(fs *flag.FlagSet, args ...string) options {
var o options
fs.StringVar(&o.namespace, "namespace", "", "The namespace to listen in")
err := fs.Parse(args)
if err != nil {
logrus.WithError(err).Fatal("Invalid options")
}
return o
}
func main() {
logrusutil.ComponentInit("lighthouse-foghorn")
scheme := runtime.NewScheme()
if err := lighthousev1alpha1.AddToScheme(scheme); err != nil {
logrus.WithError(err).Fatal("Failed to register scheme")
}
o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
logrus.WithError(err).Fatal("Invalid options")
}
cfg, err := clients.GetConfig("", "")
if err != nil {
logrus.WithError(err).Fatal("Could not create kubeconfig")
}
mgr, err := ctrl.NewManager(cfg, ctrl.Options{Scheme: scheme, Namespace: o.namespace})
if err != nil {
logrus.WithError(err).Fatal("Unable to start manager")
}
reconciler, err := foghorn.NewLighthouseJobReconciler(mgr.GetClient(), mgr.GetScheme(), o.namespace)
if err != nil {
logrus.WithError(err).Fatal("Unable to instantiate reconciler")
}
if err = reconciler.SetupWithManager(mgr); err != nil {
logrus.WithError(err).Fatal("Unable to create controller")
}
defer reconciler.ConfigMapWatcher.Stop()
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
logrus.WithError(err).Fatal("Problem running manager")
}
}