Skip to content

Commit

Permalink
Cleanup role rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Jun 4, 2024
1 parent 7629bb3 commit 1dba9bf
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions controllers/tenant/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func reconcileRole(obj pipeline.Object, data *pipeline.Context) pipeline.Result
return pipeline.Result{Err: fmt.Errorf("object is not a tenant")}
}

rns := []string{tenant.Name}
cls := v1alpha1.ClusterList{}
if err := data.Client.List(data.Context, &cls,
client.InNamespace(tenant.Namespace),
client.MatchingFields{"spec.tenantRef.name": tenant.Name},
); err != nil {
return pipeline.Result{Err: fmt.Errorf("failed to list clusters: %w", err)}
}
clusterNames := make([]string, 0, len(cls.Items))
for _, c := range cls.Items {
rns = append(rns, c.Name)
clusterNames = append(clusterNames, c.Name)
}

role := rbacv1.Role{
Expand All @@ -41,13 +41,20 @@ func reconcileRole(obj pipeline.Object, data *pipeline.Context) pipeline.Result
{
APIGroups: []string{synv1alpha1.GroupVersion.Group},
Verbs: []string{"get"},
Resources: []string{"tenants", "clusters"},
ResourceNames: rns,
}, {
Resources: []string{"tenants"},
ResourceNames: []string{tenant.Name},
},
{
APIGroups: []string{synv1alpha1.GroupVersion.Group},
Verbs: []string{"get"},
Resources: []string{"clusters"},
ResourceNames: clusterNames,
},
{
APIGroups: []string{synv1alpha1.GroupVersion.Group},
Verbs: []string{"get", "update", "patch"},
Resources: []string{"clusters/status"},
ResourceNames: rns,
ResourceNames: clusterNames,
},
}
return controllerutil.SetControllerReference(tenant, &role, data.Client.Scheme())
Expand Down

0 comments on commit 1dba9bf

Please sign in to comment.