-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
78 lines (63 loc) · 2.02 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
package main
import (
"flag"
"os"
"path/filepath"
"github.com/ca-gip/kubi-members/internal/controller"
"github.com/ca-gip/kubi-members/internal/ldap"
membersclientset "github.com/ca-gip/kubi-members/pkg/generated/clientset/versioned"
projectclientset "github.com/ca-gip/kubi/pkg/generated/clientset/versioned"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
)
var (
masterURL string
kubeconfig string
)
func main() {
flag.StringVar(&kubeconfig, "kubeconfig", defaultKubeconfig(), "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
klog.InitFlags(nil)
flag.Parse()
// Load kube config
cfg, err := rest.InClusterConfig()
if err != nil {
cfg, err = clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
klog.Fatalf("Error building kubeconfig: %s", err.Error())
}
}
// Generate clientsets
configMapClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Error building kubernetes configMapClient: %s", err.Error())
}
projectClient, err := projectclientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Error building kubernetes projectClient: %s", err.Error())
}
membersClient, err := membersclientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Error building kubernetes membersClient: %s", err.Error())
}
klog.Info("Creating LDAP client")
ldapClient := ldap.NewLdap()
controller := controller.NewController(configMapClient, projectClient, membersClient, ldapClient)
if err := controller.Run(); err != nil {
klog.Fatalf("Error running controller: %s", err.Error())
}
}
func defaultKubeconfig() string {
fname := os.Getenv("KUBECONFIG")
if fname != "" {
return fname
}
home, err := os.UserHomeDir()
if err != nil {
klog.Warningf("failed to get home directory: %v", err)
return ""
}
return filepath.Join(home, ".kube", "config")
}