@@ -11,16 +11,14 @@ import (
11
11
"k8s.io/apimachinery/pkg/runtime/schema"
12
12
)
13
13
14
- func TestGenerateRBAC (t * testing.T ) {
15
- // Use these test cases to check if Generate function is correct
14
+ func TestGenerateAgentRBACManifests (t * testing.T ) {
16
15
testCases := []struct {
17
- expectedClusterRoles []rbac.ClusterRole
18
- expectedClusterRoleBindings []rbac.ClusterRoleBinding
19
- dataGatherers []agent.DataGatherer
20
- description string
16
+ description string
17
+ dataGatherers []agent.DataGatherer
18
+ expectedAgentRBACManifests AgentRBACManifests
21
19
}{
22
20
{
23
- description : "Generate RBAC struct for pods datagatherer " ,
21
+ description : "Generate ClusterRole and ClusterRoleBinding for simple pod dg case " ,
24
22
dataGatherers : []agent.DataGatherer {
25
23
{
26
24
Name : "k8s/pods" ,
@@ -32,151 +30,56 @@ func TestGenerateRBAC(t *testing.T) {
32
30
},
33
31
},
34
32
},
35
- {
36
- Name : "k8s/secrets" ,
37
- Kind : "k8s-dynamic" ,
38
- Config : & k8s.ConfigDynamic {
39
- GroupVersionResource : schema.GroupVersionResource {
40
- Version : "v1" ,
41
- Resource : "secrets" ,
42
- },
43
- },
44
- },
45
- {
46
- Name : "k8s/awspcaissuer" ,
47
- Kind : "k8s-dynamic" ,
48
- Config : & k8s.ConfigDynamic {
49
- GroupVersionResource : schema.GroupVersionResource {
50
- Group : "awspca.cert-manager.io" ,
51
- Version : "v1" ,
52
- Resource : "awspcaissuers" ,
53
- },
54
- },
55
- },
56
33
},
57
- expectedClusterRoles : []rbac.ClusterRole {
58
- {
59
- TypeMeta : metav1.TypeMeta {
60
- Kind : "ClusterRole" ,
61
- APIVersion : "rbac.authorization.k8s.io/v1" ,
62
- },
63
- ObjectMeta : metav1.ObjectMeta {
64
- Name : "jetstack-secure-agent-pods-reader" ,
65
- },
66
- Rules : []rbac.PolicyRule {
67
- {
68
- Verbs : []string {"get" , "list" , "watch" },
69
- APIGroups : []string {"" },
70
- Resources : []string {"pods" },
34
+ expectedAgentRBACManifests : AgentRBACManifests {
35
+ ClusterRoles : []rbac.ClusterRole {
36
+ {
37
+ TypeMeta : metav1.TypeMeta {
38
+ Kind : "ClusterRole" ,
39
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
71
40
},
72
- },
73
- },
74
- {
75
- TypeMeta : metav1.TypeMeta {
76
- Kind : "ClusterRole" ,
77
- APIVersion : "rbac.authorization.k8s.io/v1" ,
78
- },
79
- ObjectMeta : metav1.ObjectMeta {
80
- Name : "jetstack-secure-agent-secrets-reader" ,
81
- },
82
- Rules : []rbac.PolicyRule {
83
- {
84
- Verbs : []string {"get" , "list" , "watch" },
85
- APIGroups : []string {"" },
86
- Resources : []string {"secrets" },
41
+ ObjectMeta : metav1.ObjectMeta {
42
+ Name : "jetstack-secure-agent-pods-reader" ,
87
43
},
88
- },
89
- },
90
- {
91
- TypeMeta : metav1.TypeMeta {
92
- Kind : "ClusterRole" ,
93
- APIVersion : "rbac.authorization.k8s.io/v1" ,
94
- },
95
- ObjectMeta : metav1.ObjectMeta {
96
- Name : "jetstack-secure-agent-awspcaissuers-reader" ,
97
- },
98
- Rules : []rbac.PolicyRule {
99
- {
100
- Verbs : []string {"get" , "list" , "watch" },
101
- APIGroups : []string {"awspca.cert-manager.io" },
102
- Resources : []string {"awspcaissuers" },
44
+ Rules : []rbac.PolicyRule {
45
+ {
46
+ Verbs : []string {"get" , "list" , "watch" },
47
+ APIGroups : []string {"" },
48
+ Resources : []string {"pods" },
49
+ },
103
50
},
104
51
},
105
52
},
106
- },
107
- expectedClusterRoleBindings : []rbac.ClusterRoleBinding {
108
- {
109
- TypeMeta : metav1.TypeMeta {
110
- Kind : "ClusterRoleBinding" ,
111
- APIVersion : "rbac.authorization.k8s.io/v1" ,
112
- },
113
- ObjectMeta : metav1.ObjectMeta {
114
- Name : "jetstack-secure-agent-pods-reader" ,
115
- },
116
- Subjects : []rbac.Subject {
117
- {
118
- Kind : "ServiceAccount" ,
119
- Name : "agent" ,
120
- Namespace : "jetstack-secure" ,
53
+ ClusterRoleBindings : []rbac.ClusterRoleBinding {
54
+ {
55
+ TypeMeta : metav1.TypeMeta {
56
+ Kind : "ClusterRoleBinding" ,
57
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
121
58
},
122
- },
123
- RoleRef : rbac.RoleRef {
124
- Kind : "ClusterRole" ,
125
- Name : "jetstack-secure-agent-pods-reader" ,
126
- APIGroup : "rbac.authorization.k8s.io" ,
127
- },
128
- },
129
- {
130
- TypeMeta : metav1.TypeMeta {
131
- Kind : "ClusterRoleBinding" ,
132
- APIVersion : "rbac.authorization.k8s.io/v1" ,
133
- },
134
- ObjectMeta : metav1.ObjectMeta {
135
- Name : "jetstack-secure-agent-secrets-reader" ,
136
- },
137
- Subjects : []rbac.Subject {
138
- {
139
- Kind : "ServiceAccount" ,
140
- Name : "agent" ,
141
- Namespace : "jetstack-secure" ,
59
+ ObjectMeta : metav1.ObjectMeta {
60
+ Name : "jetstack-secure-agent-pods-reader" ,
142
61
},
143
- },
144
- RoleRef : rbac.RoleRef {
145
- Kind : "ClusterRole" ,
146
- Name : "jetstack-secure-agent-secrets-reader" ,
147
- APIGroup : "rbac.authorization.k8s.io" ,
148
- },
149
- },
150
- {
151
- TypeMeta : metav1.TypeMeta {
152
- Kind : "ClusterRoleBinding" ,
153
- APIVersion : "rbac.authorization.k8s.io/v1" ,
154
- },
155
- ObjectMeta : metav1.ObjectMeta {
156
- Name : "jetstack-secure-agent-awspcaissuers-reader" ,
157
- },
158
- Subjects : []rbac.Subject {
159
- {
160
- Kind : "ServiceAccount" ,
161
- Name : "agent" ,
162
- Namespace : "jetstack-secure" ,
62
+ Subjects : []rbac.Subject {
63
+ {
64
+ Kind : "ServiceAccount" ,
65
+ Name : "agent" ,
66
+ Namespace : "jetstack-secure" ,
67
+ },
68
+ },
69
+ RoleRef : rbac.RoleRef {
70
+ Kind : "ClusterRole" ,
71
+ Name : "jetstack-secure-agent-pods-reader" ,
72
+ APIGroup : "rbac.authorization.k8s.io" ,
163
73
},
164
- },
165
- RoleRef : rbac.RoleRef {
166
- Kind : "ClusterRole" ,
167
- Name : "jetstack-secure-agent-awspcaissuers-reader" ,
168
- APIGroup : "rbac.authorization.k8s.io" ,
169
74
},
170
75
},
171
76
},
172
77
},
173
78
}
174
79
175
80
for _ , input := range testCases {
176
- gotClusterRoles := GenerateClusterRoles (input .dataGatherers )
177
- gotClusterRoleBindings := GenerateClusterRoleBindings (gotClusterRoles )
81
+ got := GenerateAgentRBACManifests (input .dataGatherers )
178
82
179
- td .Cmp (t , input .expectedClusterRoles , gotClusterRoles )
180
- td .Cmp (t , input .expectedClusterRoleBindings , gotClusterRoleBindings )
83
+ td .Cmp (t , input .expectedAgentRBACManifests , got )
181
84
}
182
85
}
0 commit comments