@@ -19,6 +19,7 @@ type AgentRBACManifests struct {
19
19
RoleBindings []rbac.RoleBinding
20
20
}
21
21
22
+ //func GenerateAgentRBACManifests(dataGatherers []agent.DataGatherer, konwnNamespaces []string) AgentRBACManifests {
22
23
func GenerateAgentRBACManifests (dataGatherers []agent.DataGatherer ) AgentRBACManifests {
23
24
// create a new AgentRBACManifest struct
24
25
var AgentRBACManifests AgentRBACManifests
@@ -31,6 +32,7 @@ func GenerateAgentRBACManifests(dataGatherers []agent.DataGatherer) AgentRBACMan
31
32
dyConfig := dg .Config .(* k8s.ConfigDynamic )
32
33
metadataName := fmt .Sprintf ("jetstack-secure-agent-%s-reader" , dyConfig .GroupVersionResource .Resource )
33
34
35
+ // always do this...
34
36
AgentRBACManifests .ClusterRoles = append (AgentRBACManifests .ClusterRoles , rbac.ClusterRole {
35
37
TypeMeta : metav1.TypeMeta {
36
38
Kind : "ClusterRole" ,
@@ -48,30 +50,65 @@ func GenerateAgentRBACManifests(dataGatherers []agent.DataGatherer) AgentRBACMan
48
50
},
49
51
})
50
52
51
- AgentRBACManifests .ClusterRoleBindings = append (AgentRBACManifests .ClusterRoleBindings , rbac.ClusterRoleBinding {
52
- TypeMeta : metav1.TypeMeta {
53
- Kind : "ClusterRoleBinding" ,
54
- APIVersion : "rbac.authorization.k8s.io/v1" ,
55
- },
53
+ // if dyConfig.IncludeNamespaces has more than 0 items in it
54
+ // then, for each namespace create a rbac.RoleBinding in that namespace
55
+ // AgentRBACManifests.RoleBindings = append(...)
56
+ if len (dyConfig .IncludeNamespaces ) != 0 {
57
+ for _ , ns := range dyConfig .IncludeNamespaces {
58
+ AgentRBACManifests .RoleBindings = append (AgentRBACManifests .RoleBindings , rbac.RoleBinding {
59
+ TypeMeta : metav1.TypeMeta {
60
+ Kind : "RoleBinding" ,
61
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
62
+ },
56
63
57
- ObjectMeta : metav1.ObjectMeta {
58
- Name : metadataName ,
59
- },
64
+ ObjectMeta : metav1.ObjectMeta {
65
+ Name : metadataName ,
66
+ Namespace : ns ,
67
+ },
60
68
61
- Subjects : []rbac.Subject {
62
- {
63
- Kind : "ServiceAccount" ,
64
- Name : "agent" ,
65
- Namespace : "jetstack-secure" ,
69
+ Subjects : []rbac.Subject {
70
+ {
71
+ Kind : "ServiceAccount" ,
72
+ Name : "agent" ,
73
+ Namespace : "jetstack-secure" ,
74
+ },
75
+ },
76
+
77
+ RoleRef : rbac.RoleRef {
78
+ Kind : "ClusterRole" ,
79
+ Name : metadataName ,
80
+ APIGroup : "rbac.authorization.k8s.io" ,
81
+ },
82
+ })
83
+ }
84
+ } else {
85
+ // only do this if the dg does not have IncludeNamespaces set
86
+ AgentRBACManifests .ClusterRoleBindings = append (AgentRBACManifests .ClusterRoleBindings , rbac.ClusterRoleBinding {
87
+ TypeMeta : metav1.TypeMeta {
88
+ Kind : "ClusterRoleBinding" ,
89
+ APIVersion : "rbac.authorization.k8s.io/v1" ,
66
90
},
67
- },
68
91
69
- RoleRef : rbac.RoleRef {
70
- Kind : "ClusterRole" ,
71
- Name : metadataName ,
72
- APIGroup : "rbac.authorization.k8s.io" ,
73
- },
74
- })
92
+ ObjectMeta : metav1.ObjectMeta {
93
+ Name : metadataName ,
94
+ },
95
+
96
+ Subjects : []rbac.Subject {
97
+ {
98
+ Kind : "ServiceAccount" ,
99
+ Name : "agent" ,
100
+ Namespace : "jetstack-secure" ,
101
+ },
102
+ },
103
+
104
+ RoleRef : rbac.RoleRef {
105
+ Kind : "ClusterRole" ,
106
+ Name : metadataName ,
107
+ APIGroup : "rbac.authorization.k8s.io" ,
108
+ },
109
+ })
110
+ }
111
+
75
112
}
76
113
77
114
return AgentRBACManifests
0 commit comments