-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
84 lines (68 loc) · 2.33 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
79
80
81
82
83
84
package main
import (
"flag"
"os"
"os/signal"
"time"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
clientset "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned"
sharedInformers "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/informers/externalversions"
"github.com/K8sNetworkPlumbingWG/k8s-net-attach-def-controller/pkg/controller"
)
var (
master string
kubeconfig string
// defines default resync period between k8s API server and controller
syncPeriod = time.Second * 5
)
func main() {
flag.StringVar(&master, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Required if out-of-cluster.")
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Required if out-of-cluster.")
flag.Parse()
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
f2.Value.Set(value)
}
})
cfg, err := clientcmd.BuildConfigFromFlags(master, kubeconfig)
if err != nil {
klog.Fatalf("error building kubeconfig: %s", err.Error())
}
k8sClientSet, err := kubernetes.NewForConfig(cfg)
if err != nil {
klog.Fatalf("error creating kubernetes clientset: %s", err.Error())
}
netAttachDefClientSet, err := clientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("error creating net-attach-def clientset: %s", err.Error())
}
netAttachDefInformerFactory := sharedInformers.NewSharedInformerFactory(netAttachDefClientSet, syncPeriod)
k8sInformerFactory := informers.NewSharedInformerFactory(k8sClientSet, syncPeriod)
networkController := controller.NewNetworkController(
k8sClientSet,
netAttachDefClientSet,
netAttachDefInformerFactory.K8sCniCncfIo().V1().NetworkAttachmentDefinitions(),
k8sInformerFactory.Core().V1().Services(),
k8sInformerFactory.Core().V1().Pods(),
k8sInformerFactory.Core().V1().Endpoints(),
)
stopChan := make(chan struct{})
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
close(stopChan)
<-c
os.Exit(1)
}()
netAttachDefInformerFactory.Start(stopChan)
k8sInformerFactory.Start(stopChan)
networkController.Start(stopChan)
}