@@ -15,23 +15,14 @@ func TestGenerateRBAC(t *testing.T) {
15
15
// Use these test cases to check if Generate function is correct
16
16
testCases := []struct {
17
17
// expectedClusterRoles is the collection of ClusterRole
18
- expectedClusterRoles []rbac.ClusterRole
19
- dataGatherers []agent.DataGatherer
20
- description string
18
+ expectedClusterRoleBindings []rbac.ClusterRoleBinding
19
+ dataGatherers []agent.DataGatherer
20
+ description string
21
21
}{
22
22
{
23
23
description : "Generate RBAC struct for pods datagatherer" ,
24
24
dataGatherers : []agent.DataGatherer {
25
- {
26
- Name : "k8s/pods" ,
27
- Kind : "k8s-dynamic" ,
28
- Config : & k8s.ConfigDynamic {
29
- GroupVersionResource : schema.GroupVersionResource {
30
- Version : "v1" ,
31
- Resource : "pods" ,
32
- },
33
- },
34
- },
25
+
35
26
{
36
27
Name : "k8s/secrets" ,
37
28
Kind : "k8s-dynamic" ,
@@ -42,65 +33,31 @@ func TestGenerateRBAC(t *testing.T) {
42
33
},
43
34
},
44
35
},
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
36
},
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" },
71
- },
72
- },
73
- },
37
+ expectedClusterRoleBindings : []rbac.ClusterRoleBinding {
38
+
74
39
{
75
40
TypeMeta : metav1.TypeMeta {
76
- Kind : "ClusterRole " ,
41
+ Kind : "ClusterRoleBinding " ,
77
42
APIVersion : "rbac.authorization.k8s.io/v1" ,
78
43
},
44
+
79
45
ObjectMeta : metav1.ObjectMeta {
80
- Name : "jetstack-secure-agent-secrets -reader" ,
46
+ Name : "jetstack-secure-agent-ClusterRole -reader" ,
81
47
},
82
- Rules : []rbac.PolicyRule {
48
+
49
+ Subjects : []rbac.Subject {
83
50
{
84
- Verbs : [] string { "get" , "list" , "watch" } ,
85
- APIGroups : [] string { "" } ,
86
- Resources : [] string { "secrets" } ,
51
+ Kind : "ServiceAccount" ,
52
+ Name : "agent" ,
53
+ Namespace : "jetstack-secure" ,
87
54
},
88
55
},
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" },
103
- },
56
+
57
+ RoleRef : rbac.RoleRef {
58
+ Kind : "ClusterRole" ,
59
+ Name : "jetstack-secure-agent-secret-reader" ,
60
+ APIGroup : "rbac.authorization.k8s.io" ,
104
61
},
105
62
},
106
63
},
@@ -110,9 +67,10 @@ func TestGenerateRBAC(t *testing.T) {
110
67
111
68
for _ , input := range testCases {
112
69
got := GenerateRoles (input .dataGatherers )
113
- if diff , equal := messagediff .PrettyDiff (input .expectedClusterRoles , got ); ! equal {
70
+ toBeTest := GenerateBindings (got )
71
+ if diff , equal := messagediff .PrettyDiff (input .expectedClusterRoleBindings , toBeTest ); ! equal {
114
72
t .Errorf ("%s:\n %s" , input .description , diff )
115
- t .Fatalf ("unexpected difference in RBAC cluster role: \n got \n %v\n want\n %v" , got , input .expectedClusterRoles )
73
+ t .Fatalf ("unexpected difference in RBAC cluster role: \n got \n %v\n want\n %v" , got , input .expectedClusterRoleBindings )
116
74
}
117
75
}
118
76
}
0 commit comments