-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
72 lines (56 loc) · 1.88 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"
"log"
"os"
"time"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"github.com/MYOB-Technology/ops-kube-db-operator/pkg/controller"
dbClientSet "github.com/MYOB-Technology/ops-kube-db-operator/pkg/client/clientset/versioned"
dbInformer "github.com/MYOB-Technology/ops-kube-db-operator/pkg/client/informers/externalversions"
)
var version = "snapshot"
func main() {
log.Printf("rds-controller version: %v", version)
// read kube config file from flag
var kubeconfig string
flag.StringVar(&kubeconfig, "kubeconfig", "", "kubeconfig file")
flag.Parse()
// if no flag has been passed, read kubeconfig file from environment
if kubeconfig == "" {
kubeconfig = os.Getenv("KUBECONFIG")
}
var config *rest.Config
var err error
// if flag has not been passed and env not set, presume running in cluster
if kubeconfig != "" {
log.Printf("using kubeconfig %v", kubeconfig)
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
log.Printf("running inside cluster")
config, err = rest.InClusterConfig()
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatalf("error creating kubernetes client: %v", err)
}
dbClient, err := dbClientSet.NewForConfig(config)
if err != nil {
log.Fatalf("error creating db client: %v", err)
}
// dbInformerFactory acts like a cache for db resources like above
dbInformerFactory := dbInformer.NewSharedInformerFactory(dbClient, 10*time.Minute)
dbConfig, err := controller.NewDBInstanceConfig()
if err != nil {
log.Fatalf("%v", err)
}
// this controller will deal with RDS dbs
rdsController := controller.New(client, dbClient, dbInformerFactory, dbConfig)
// start go routines with our informers
go dbInformerFactory.Start(nil)
if err = rdsController.Run(2, nil); err != nil {
log.Fatalf("Error running controller: %v", err)
}
}