-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathmain.go
75 lines (64 loc) · 1.92 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
package main
import (
"log"
"os"
routeClient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/stakater/IngressMonitorController/pkg/config"
"github.com/stakater/IngressMonitorController/pkg/controller"
"github.com/stakater/IngressMonitorController/pkg/kube"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
currentNamespace := os.Getenv("KUBERNETES_NAMESPACE")
if len(currentNamespace) == 0 {
currentNamespace = v1.NamespaceAll
log.Println("Warning: KUBERNETES_NAMESPACE is unset, will monitor ingresses in all namespaces.")
}
var kubeClient kubernetes.Interface
cfg, err := rest.InClusterConfig()
if err != nil {
kubeClient = kube.GetClientOutOfCluster()
} else {
kubeClient = kube.GetClient()
}
// fetche and create controller config from file
config := config.GetControllerConfig()
var resource = "ingresses"
var restClient rest.Interface
var osClient *routeClient.RouteV1Client
if kube.IsOpenShift(kubeClient.(*kubernetes.Clientset)) {
resource = "routes"
// Create an OpenShift build/v1 client.
osClient, err = routeClient.NewForConfig(cfg)
if err != nil {
log.Panic(err.Error())
}
restClient = osClient.RESTClient()
} else {
restClient = kubeClient.ExtensionsV1beta1().RESTClient()
}
// create the monitoring controller
controller := controller.NewMonitorController(currentNamespace, kubeClient, config, resource, restClient)
// Now let's start the controller
stop := make(chan struct{})
defer close(stop)
go controller.Run(1, stop)
// Wait forever
select {}
}
func createInClusterConfig() *rest.Config {
config, err := rest.InClusterConfig()
if err != nil {
log.Panic(err.Error())
}
return config
}
func createKubernetesClient(config *rest.Config) *kubernetes.Clientset {
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Panic(err.Error())
}
return clientset
}