/
main.go
67 lines (55 loc) · 1.87 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
package main
import (
"context"
"os"
"os/signal"
"github.com/fluxcd/pkg/runtime/logger"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/go-logr/logr"
infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
cgoscheme "k8s.io/client-go/kubernetes/scheme"
)
func init() {
utilruntime.Must(cgoscheme.AddToScheme(scheme.Scheme))
utilruntime.Must(sourcev1.AddToScheme(scheme.Scheme))
utilruntime.Must(sourcev1b2.AddToScheme(scheme.Scheme))
utilruntime.Must(infrav1.AddToScheme(scheme.Scheme))
}
var (
// BuildSHA is the controller version
BuildSHA string
// BuildVersion is the controller build version
BuildVersion string
)
func main() {
opts := parseFlags()
log := logger.
NewLogger(opts.logOptions).
WithValues("version", BuildVersion, "sha", BuildSHA)
logger.SetLogger(log)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
dynamicClusterClient, clusterClient, err := getClusterClient()
if err != nil {
log.Error(err, "failed get cluster clients")
}
go func(log logr.Logger) {
log.Info("Starting polling server")
if err := startPollingServer(ctx, log, clusterClient, opts); err != nil {
log.Error(err, "unable to start polling server")
}
// Does not matter if it was an error or not, if this routine is done for
// unknown reasons, stop the other routine too.
cancel()
}(log.WithName("polling-server"))
informerLog := log.WithName("informer")
informerLog.Info("Starting branch-based planner informer")
if err := startInformer(ctx, informerLog, dynamicClusterClient, clusterClient); err != nil {
informerLog.Error(err, "branch-based planner informer failed")
}
// once the informer exits, make sure the goroutine above is also
// cancelled.
cancel()
}