-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
117 lines (94 loc) · 2.73 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"context"
"fmt"
"os"
"github.com/AvineshTripathi/valconf/objects"
"github.com/AvineshTripathi/valconf/validate"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
ctx := context.Background()
kubeconfig, err := clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config")
if err != nil {
fmt.Println(err)
}
clientset, err := kubernetes.NewForConfig(kubeconfig)
if err != nil {
fmt.Println(err)
}
object := objects.NewObject(ctx, clientset)
podsList, err := clientset.CoreV1().Pods("").List(ctx, v1.ListOptions{})
if err != nil {
fmt.Println(err)
}
deployList, err := clientset.AppsV1().Deployments("").List(ctx, v1.ListOptions{})
if err != nil {
fmt.Println(err)
}
serviceList, err := clientset.CoreV1().Services("").List(ctx, v1.ListOptions{})
if err != nil {
fmt.Println(err)
}
svcAccountList, err := clientset.CoreV1().ServiceAccounts("").List(ctx, v1.ListOptions{})
if err != nil {
fmt.Println(err)
}
roleList, err := clientset.RbacV1().Roles("").List(ctx, v1.ListOptions{})
if err != nil {
fmt.Println(err)
}
// optimised
// channels := [5]chan map[string]interface{}{}
// for i := 0; i<5; i++ {
// channels[i] = make(chan map[string]interface{}, 1)
// go func(index int) {
// var result map[string]interface{}
// switch index {
// case 0:
// result = map[string]interface{}{"pod": object.Pod(podsList)}
// case 1:
// result = map[string]interface{}{"deploy": object.Deployment(deployList)}
// case 2:
// result = map[string]interface{}{"svc": object.Service(serviceList)}
// case 3:
// result = map[string]interface{}{"svc_account": object.ServiceAccount(svcAccountList)}
// case 4:
// result = map[string]interface{}{"role": object.Role(roleList)}
// }
// channels[index] <- result
// }(i)
// }
// data := make([]map[string]interface{}, 5)
// for i, _ := range channels {
// result := <- channels[i]
// fmt.Println(result)
// data = append(data, result)
// }
podConf := object.Pod(podsList)
deployConf := object.Deployment(deployList)
svcConf := object.Service(serviceList)
svcAccConf := object.ServiceAccount(svcAccountList)
roleConf := object.Role(roleList)
input := map[string]interface{}{
"pod": podConf,
"deploy": deployConf,
"svc": svcConf,
"svc_account": svcAccConf,
"role": roleConf,
}
// fmt.Println(len(input))
// fmt.Println(input["pod"])
// fmt.Println()
// fmt.Println(input["deploy"])
// fmt.Println()
// fmt.Println(input["svc"])
// fmt.Println()
// fmt.Println(input["svc_account"])
// fmt.Println()
// fmt.Println(input["role"])
validate.Rego(ctx, input)
//fmt.Println(input["pod"], object.Pod(podsList))
}