@@ -27,6 +27,8 @@ import (
27
27
"github.com/openshift/operator-framework-olm/pkg/manifests"
28
28
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
29
29
30
+ corev1 "k8s.io/api/core/v1"
31
+ rbacv1 "k8s.io/api/rbac/v1"
30
32
"k8s.io/apimachinery/pkg/runtime"
31
33
"k8s.io/apimachinery/pkg/types"
32
34
@@ -67,6 +69,10 @@ func (r *PackageServerCSVReconciler) Reconcile(ctx context.Context, req ctrl.Req
67
69
log .Info ("handling current request" , "request" , req .String ())
68
70
defer log .Info ("finished request reconciliation" )
69
71
72
+ if err := ensureRBAC (r .Client , ctx , r .Namespace , log ); err != nil {
73
+ return ctrl.Result {}, err
74
+ }
75
+
70
76
var infra configv1.Infrastructure
71
77
if err := r .Client .Get (ctx , types.NamespacedName {Name : infrastructureName }, & infra ); err != nil {
72
78
return ctrl.Result {}, err
@@ -102,6 +108,21 @@ func (r *PackageServerCSVReconciler) Reconcile(ctx context.Context, req ctrl.Req
102
108
return ctrl.Result {}, nil
103
109
}
104
110
111
+ func ensureRBAC (client client.Client , ctx context.Context , namespace string , log logr.Logger ) error {
112
+ log .Info ("checking to see if required RBAC exists" )
113
+ if err := client .Get (ctx , types.NamespacedName {Name : "olm-operator-serviceaccount" , Namespace : namespace }, & corev1.ServiceAccount {}); err != nil {
114
+ return fmt .Errorf ("could not get service account:%v" , err )
115
+ }
116
+ if err := client .Get (ctx , types.NamespacedName {Name : "system:controller:operator-lifecycle-manager" }, & rbacv1.ClusterRole {}); err != nil {
117
+ return fmt .Errorf ("could not get ClusterRole:% v" , err )
118
+ }
119
+ if err := client .Get (ctx , types.NamespacedName {Name : "olm-operator-binding-openshift-operator-lifecycle-manager" }, & rbacv1.ClusterRoleBinding {}); err != nil {
120
+ return fmt .Errorf ("could not get ClusterRoleBinding: %v" , err )
121
+ }
122
+ log .Info ("confimed required RBAC exists" )
123
+ return nil
124
+ }
125
+
105
126
func reconcileCSV (log logr.Logger , image string , interval string , csv * olmv1alpha1.ClusterServiceVersion , highAvailabilityMode bool ) error {
106
127
if csv .ObjectMeta .CreationTimestamp .IsZero () {
107
128
log .Info ("attempting to create the packageserver csv" )
0 commit comments