-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (53 loc) · 2.1 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
package main
import (
"flag"
"kadeksuryam/secret-controller/pkg/signals"
"time"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
karmorclientset "github.com/kubearmor/KubeArmor/pkg/KubeArmorPolicy/client/clientset/versioned"
karmorpolicyinformer "github.com/kubearmor/KubeArmor/pkg/KubeArmorPolicy/client/informers/externalversions"
kubeinformers "k8s.io/client-go/informers"
)
var (
masterURL string
kubeconfig string
numworkers uint
)
func main() {
klog.InitFlags(nil)
flag.Parse()
ctx := signals.SetupSignalHandler()
logger := klog.FromContext(ctx)
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
logger.Error(err, "Error building kubeconfig")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
logger.Error(err, "Error building kubernetes clientset")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
karmorClient, err := karmorclientset.NewForConfig(cfg)
if err != nil {
klog.Fatalf("Error building karmor clientset: %s", err.Error())
}
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
karmorpolicyInformerFactory := karmorpolicyinformer.NewSharedInformerFactory(karmorClient, time.Second*30)
controller := NewController(ctx, kubeClient, karmorClient, kubeInformerFactory.Apps().V1().Deployments(),
kubeInformerFactory.Apps().V1().StatefulSets(),
kubeInformerFactory.Apps().V1().DaemonSets(),
karmorpolicyInformerFactory.Security().V1().KubeArmorPolicies())
kubeInformerFactory.Start(ctx.Done())
karmorpolicyInformerFactory.Start(ctx.Done())
if err = controller.Run(ctx, int(numworkers)); err != nil {
klog.Fatalf("Error running controller: %s", err.Error())
}
}
func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "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.")
flag.UintVar(&numworkers, "numworker", 2, "Number worker in the controller")
}