@@ -36,7 +36,6 @@ import (
3636 "github.com/openstack-k8s-operators/test-operator/pkg/tempest"
3737 batchv1 "k8s.io/api/batch/v1"
3838 corev1 "k8s.io/api/core/v1"
39- rbacv1 "k8s.io/api/rbac/v1"
4039 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
4140 ctrl "sigs.k8s.io/controller-runtime"
4241 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -56,20 +55,16 @@ func (r *TempestReconciler) GetLogger(ctx context.Context) logr.Logger {
5655// +kubebuilder:rbac:groups=test.openstack.org,resources=tempests,verbs=get;list;watch;create;update;patch;delete
5756// +kubebuilder:rbac:groups=test.openstack.org,resources=tempests/status,verbs=get;update;patch
5857// +kubebuilder:rbac:groups=test.openstack.org,resources=tempests/finalizers,verbs=update;patch
59- // +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete;
60- // +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
61- // +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;
6258// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;patch;update;delete;
6359// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
64-
65- // service account, role, rolebinding
66- // +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;update;patch
6760// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=roles,verbs=get;list;watch;create;update;patch
6861// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=rolebindings,verbs=get;list;watch;create;update;patch
69- // service account permissions that are needed to grant permission to the above
70- // +kubebuilder:rbac:groups="security.openshift.io",resourceNames=anyuid;privileged,resources=securitycontextconstraints,verbs=use
62+ // +kubebuilder:rbac:groups="security.openshift.io",resourceNames=anyuid;privileged;nonroot;nonroot-v2,resources=securitycontextconstraints,verbs=use
63+ // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
64+ // +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
7165// +kubebuilder:rbac:groups="",resources=pods,verbs=create;delete;get;list;patch;update;watch
72- // +kubebuilder:rbac:groups="",resources=persistentvolumeclaims,verbs=get;list;create;update;watch;patch
66+ // +kubebuilder:rbac:groups="",resources=persistentvolumeclaims,verbs=get;list;create;update;watch;patch;delete
67+ // +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;update;patch
7368
7469// Reconcile - Tempest
7570func (r * TempestReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (result ctrl.Result , _err error ) {
@@ -191,33 +186,6 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
191186 }
192187 }
193188
194- // Service account, role, binding
195- rbacRules := []rbacv1.PolicyRule {
196- {
197- APIGroups : []string {"security.openshift.io" },
198- ResourceNames : []string {"anyuid" , "privileged" },
199- Resources : []string {"securitycontextconstraints" },
200- Verbs : []string {"use" },
201- },
202- {
203- APIGroups : []string {"" },
204- Resources : []string {"pods" },
205- Verbs : []string {"create" , "get" , "list" , "watch" , "update" , "patch" , "delete" },
206- },
207- {
208- APIGroups : []string {"" },
209- Resources : []string {"persistentvolumeclaims" },
210- Verbs : []string {"get" , "list" , "create" , "update" , "watch" , "patch" },
211- },
212- }
213- rbacResult , err := common_rbac .ReconcileRbac (ctx , helper , instance , rbacRules )
214- if err != nil {
215- return rbacResult , err
216- } else if (rbacResult != ctrl.Result {}) {
217- return rbacResult , nil
218- }
219- // Service account, role, binding - end
220-
221189 serviceLabels := map [string ]string {
222190 common .AppSelector : tempest .ServiceName ,
223191 "workflowStep" : strconv .Itoa (externalWorkflowCounter ),
@@ -339,6 +307,16 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
339307 return ctrl.Result {}, err
340308 }
341309
310+ // Service account, role, binding
311+ rbacRules := GetCommonRbacRules (instance .Spec .Privileged )
312+ rbacResult , err := common_rbac .ReconcileRbac (ctx , helper , instance , rbacRules )
313+ if err != nil {
314+ return rbacResult , err
315+ } else if (rbacResult != ctrl.Result {}) {
316+ return rbacResult , nil
317+ }
318+ // Service account, role, binding - end
319+
342320 // Note(lpiwowar): Remove all the workflow merge code to webhook once it is done.
343321 // It will simplify the logic and duplicite code (Tempest vs Tobiko)
344322 if externalWorkflowCounter < len (instance .Spec .Workflow ) {
0 commit comments