@@ -139,6 +139,7 @@ type (
139139 gvr []gvr
140140 saName string
141141 IsInternal bool
142+ clusterScope bool
142143 }
143144
144145 summaryLogLevels string
@@ -1077,8 +1078,9 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
10771078 version : "v1alpha1" ,
10781079 },
10791080 },
1080- saName : store .Get ().RolloutReporterServiceAccount ,
1081- IsInternal : true ,
1081+ saName : store .Get ().RolloutReporterServiceAccount ,
1082+ IsInternal : true ,
1083+ clusterScope : true ,
10821084 }); err != nil {
10831085 return fmt .Errorf ("failed to create rollout-reporter: %w" , err )
10841086 }
@@ -2144,11 +2146,11 @@ func createReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts *Runt
21442146 return err
21452147 }
21462148
2147- if err := createReporterRBAC (repofs , resPath , opts .RuntimeName , reporterCreateOpts .saName ); err != nil {
2149+ if err := createReporterRBAC (repofs , resPath , opts .RuntimeName , reporterCreateOpts .saName , reporterCreateOpts . clusterScope ); err != nil {
21482150 return err
21492151 }
21502152
2151- if err := createReporterEventSource (repofs , resPath , opts .RuntimeName , reporterCreateOpts ); err != nil {
2153+ if err := createReporterEventSource (repofs , resPath , opts .RuntimeName , reporterCreateOpts , reporterCreateOpts . clusterScope ); err != nil {
21522154 return err
21532155 }
21542156
@@ -2239,7 +2241,7 @@ func getArgoCDTokenSecret(ctx context.Context, kubeContext, namespace string, in
22392241 })
22402242}
22412243
2242- func createReporterRBAC (repofs fs.FS , path , runtimeName , saName string ) error {
2244+ func createReporterRBAC (repofs fs.FS , path , runtimeName , saName string , clusterScope bool ) error {
22432245 serviceAccount := & v1.ServiceAccount {
22442246 TypeMeta : metav1.TypeMeta {
22452247 Kind : "ServiceAccount" ,
@@ -2251,15 +2253,25 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string) error {
22512253 },
22522254 }
22532255
2256+ roleKind := "Role"
2257+ roleMeta := metav1.ObjectMeta {
2258+ Name : saName ,
2259+ Namespace : runtimeName ,
2260+ }
2261+
2262+ if clusterScope {
2263+ roleKind = "ClusterRole"
2264+ roleMeta = metav1.ObjectMeta {
2265+ Name : saName ,
2266+ }
2267+ }
2268+
22542269 role := & rbacv1.Role {
22552270 TypeMeta : metav1.TypeMeta {
2256- Kind : "Role" ,
2271+ Kind : roleKind ,
22572272 APIVersion : "rbac.authorization.k8s.io/v1" ,
22582273 },
2259- ObjectMeta : metav1.ObjectMeta {
2260- Name : saName ,
2261- Namespace : runtimeName ,
2262- },
2274+ ObjectMeta : roleMeta ,
22632275 Rules : []rbacv1.PolicyRule {
22642276 {
22652277 APIGroups : []string {"*" },
@@ -2269,15 +2281,25 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string) error {
22692281 },
22702282 }
22712283
2284+ roleBindingKind := "RoleBinding"
2285+ roleBindingMeta := metav1.ObjectMeta {
2286+ Name : saName ,
2287+ Namespace : runtimeName ,
2288+ }
2289+
2290+ if clusterScope {
2291+ roleBindingKind = "ClusterRoleBinding"
2292+ roleBindingMeta = metav1.ObjectMeta {
2293+ Name : saName ,
2294+ }
2295+ }
2296+
22722297 roleBinding := rbacv1.RoleBinding {
22732298 TypeMeta : metav1.TypeMeta {
2274- Kind : "RoleBinding" ,
2299+ Kind : roleBindingKind ,
22752300 APIVersion : "rbac.authorization.k8s.io/v1" ,
22762301 },
2277- ObjectMeta : metav1.ObjectMeta {
2278- Name : saName ,
2279- Namespace : runtimeName ,
2280- },
2302+ ObjectMeta : roleBindingMeta ,
22812303 Subjects : []rbacv1.Subject {
22822304 {
22832305 Kind : "ServiceAccount" ,
@@ -2286,7 +2308,7 @@ func createReporterRBAC(repofs fs.FS, path, runtimeName, saName string) error {
22862308 },
22872309 },
22882310 RoleRef : rbacv1.RoleRef {
2289- Kind : "Role" ,
2311+ Kind : roleKind ,
22902312 Name : saName ,
22912313 },
22922314 }
@@ -2316,7 +2338,7 @@ func createEventsReporterEventSource(repofs fs.FS, path, namespace string, insec
23162338 return repofs .WriteYamls (repofs .Join (path , "event-source.yaml" ), eventSource )
23172339}
23182340
2319- func createReporterEventSource (repofs fs.FS , path , namespace string , reporterCreateOpts reporterCreateOptions ) error {
2341+ func createReporterEventSource (repofs fs.FS , path , namespace string , reporterCreateOpts reporterCreateOptions , clusterScope bool ) error {
23202342 var eventSource * aev1alpha1.EventSource
23212343 var options * eventsutil.CreateEventSourceOptions
23222344
@@ -2333,12 +2355,18 @@ func createReporterEventSource(repofs fs.FS, path, namespace string, reporterCre
23332355 Resource : map [string ]eventsutil.CreateResourceEventSourceOptions {},
23342356 }
23352357
2358+ resourceNamespace := namespace
2359+
2360+ if clusterScope {
2361+ resourceNamespace = ""
2362+ }
2363+
23362364 for i , name := range resourceNames {
23372365 options .Resource [name ] = eventsutil.CreateResourceEventSourceOptions {
23382366 Group : reporterCreateOpts .gvr [i ].group ,
23392367 Version : reporterCreateOpts .gvr [i ].version ,
23402368 Resource : reporterCreateOpts .gvr [i ].resourceName ,
2341- Namespace : namespace ,
2369+ Namespace : resourceNamespace ,
23422370 }
23432371 }
23442372
0 commit comments