@@ -11,6 +11,99 @@ import (
11
11
"k8s.io/apimachinery/pkg/runtime/schema"
12
12
)
13
13
14
+ func TestGenerateAgentRBACManifestsString (t * testing.T ) {
15
+ testCases := []struct {
16
+ description string
17
+ dataGatherers []agent.DataGatherer
18
+ expectedRBACManifests string
19
+ }{
20
+ {
21
+ description : "Generate ClusterRole and ClusterRoleBinding for simple pod dg use case" ,
22
+ dataGatherers : []agent.DataGatherer {
23
+ {
24
+ Name : "k8s/pods" ,
25
+ Kind : "k8s-dynamic" ,
26
+ Config : & k8s.ConfigDynamic {
27
+ GroupVersionResource : schema.GroupVersionResource {
28
+ Version : "v1" ,
29
+ Resource : "pods" ,
30
+ },
31
+ },
32
+ },
33
+ },
34
+ expectedRBACManifests : `
35
+ apiVersion: rbac.authorization.k8s.io/v1
36
+ kind: ClusterRole
37
+ metadata:
38
+ name: jetstack-secure-agent-pods-reader
39
+ rules:
40
+ - apiGroups: [""]
41
+ resources: ["pods"]
42
+ verbs: ["get", "list", "watch"]
43
+ ---
44
+ apiVersion: rbac.authorization.k8s.io/v1
45
+ kind: ClusterRoleBinding
46
+ metadata:
47
+ name: jetstack-secure-agent-pods-reader
48
+ roleRef:
49
+ kind: ClusterRole
50
+ name: jetstack-secure-agent-pods-reader
51
+ apiGroup: rbac.authorization.k8s.io
52
+ subjects:
53
+ - kind: ServiceAccount
54
+ name: agent
55
+ namespace: jetstack-secure
56
+ ` ,
57
+ },
58
+ {
59
+ description : "Generate ClusterRole and RoleBinding for simple pod dg with include namespace \" foobar\" " ,
60
+ dataGatherers : []agent.DataGatherer {
61
+ {
62
+ Name : "k8s/pods" ,
63
+ Kind : "k8s-dynamic" ,
64
+ Config : & k8s.ConfigDynamic {
65
+ IncludeNamespaces : []string {"foobar" },
66
+ GroupVersionResource : schema.GroupVersionResource {
67
+ Version : "v1" ,
68
+ Resource : "pods" ,
69
+ },
70
+ },
71
+ },
72
+ },
73
+ expectedRBACManifests : `
74
+ apiVersion: rbac.authorization.k8s.io/v1
75
+ kind: ClusterRole
76
+ metadata:
77
+ name: jetstack-secure-agent-pods-reader
78
+ rules:
79
+ - apiGroups: [""]
80
+ resources: ["pods"]
81
+ verbs: ["get", "list", "watch"]
82
+ ---
83
+ apiVersion: rbac.authorization.k8s.io/v1
84
+ kind: RoleBinding
85
+ metadata:
86
+ name: jetstack-secure-agent-pods-reader
87
+ namespace: foobar
88
+ roleRef:
89
+ kind: ClusterRole
90
+ name: jetstack-secure-agent-pods-reader
91
+ apiGroup: rbac.authorization.k8s.io
92
+ subjects:
93
+ - kind: ServiceAccount
94
+ name: agent
95
+ namespace: jetstack-secure
96
+ ` ,
97
+ },
98
+ }
99
+
100
+ for _ , input := range testCases {
101
+ got := generateFullManifest (input .dataGatherers )
102
+
103
+ td .Cmp (t , input .expectedRBACManifests , got )
104
+ }
105
+ }
106
+
14
107
func TestGenerateAgentRBACManifests (t * testing.T ) {
15
108
testCases := []struct {
16
109
description string
0 commit comments