-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
71 lines (57 loc) · 1.81 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
package main
import (
"flag"
"log"
"time"
"github.com/SAP/stewardci-core/pkg/k8s"
"github.com/SAP/stewardci-core/pkg/signals"
tenantctl "github.com/SAP/stewardci-core/pkg/tenantctl"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"knative.dev/pkg/system"
)
var kubeconfig string
// Time to wait until the next resync takes place.
// Resync is only required if events got lost or if the controller restarted (and missed events).
const resyncPeriod = 1 * time.Minute
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.LUTC | log.Lshortfile)
flag.StringVar(&kubeconfig, "kubeconfig", "", "path to Kubernetes config file")
flag.Parse()
}
func main() {
// creates the in-cluster config
var config *rest.Config
var err error
if kubeconfig == "" {
log.Printf("In cluster")
config, err = rest.InClusterConfig()
if err != nil {
log.Printf("Hint: You can use parameter '-kubeconfig' for local testing. See --help")
panic(err.Error())
}
} else {
log.Printf("Outside cluster")
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
panic(err.Error())
}
}
system.Namespace() // ensure that namespace is set in environment
log.Printf("Create Factory (resync period: %s)", resyncPeriod.String())
factory := k8s.NewClientFactory(config, resyncPeriod)
log.Printf("Provide metrics")
metrics := tenantctl.NewMetrics()
metrics.StartServer()
log.Printf("Create Controller")
controller := tenantctl.NewController(factory, metrics)
log.Printf("Create Signal Handler")
stopCh := signals.SetupSignalHandler()
log.Printf("Start Informer")
factory.StewardInformerFactory().Start(stopCh)
log.Printf("Run controller")
if err = controller.Run(2, stopCh); err != nil {
log.Fatalf("Error running controller: %s", err.Error())
}
}