Skip to content

Commit cf925f9

Browse files
anik120openshift-cherrypick-robot
authored andcommitted
(psm) Wait for required RBAC before creating packageserver CSV
Motivation: https://issues.redhat.com/browse/OCPBUGS-23744 PackerServer ClusterOperator becomes unavailable momentarily on OCP upgrades, due to initial authentication blips. Even though the ClusterOperator heals eventually, ClusterOperator going down requires cluster admins to [react immediately](https://github.com/openshift/api/blob/c3f7566f6ef636bb7cf9549bf47112844285989e/config/v1/types_cluster_operator.go#L149-L153). Admins should not be paged for something that we know will heal eventually, This also shows up ~30% of the time in OCP CI as a failure since the healing does not take place within the allocated wait time.
1 parent 0e8b957 commit cf925f9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/package-server-manager/controller.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"github.com/openshift/operator-framework-olm/pkg/manifests"
2828
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2929

30+
corev1 "k8s.io/api/core/v1"
31+
rbacv1 "k8s.io/api/rbac/v1"
3032
"k8s.io/apimachinery/pkg/runtime"
3133
"k8s.io/apimachinery/pkg/types"
3234

@@ -67,6 +69,10 @@ func (r *PackageServerCSVReconciler) Reconcile(ctx context.Context, req ctrl.Req
6769
log.Info("handling current request", "request", req.String())
6870
defer log.Info("finished request reconciliation")
6971

72+
if err := ensureRBAC(r.Client, ctx, r.Namespace, log); err != nil {
73+
return ctrl.Result{}, err
74+
}
75+
7076
var infra configv1.Infrastructure
7177
if err := r.Client.Get(ctx, types.NamespacedName{Name: infrastructureName}, &infra); err != nil {
7278
return ctrl.Result{}, err
@@ -102,6 +108,21 @@ func (r *PackageServerCSVReconciler) Reconcile(ctx context.Context, req ctrl.Req
102108
return ctrl.Result{}, nil
103109
}
104110

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+
105126
func reconcileCSV(log logr.Logger, image string, interval string, csv *olmv1alpha1.ClusterServiceVersion, highAvailabilityMode bool) error {
106127
if csv.ObjectMeta.CreationTimestamp.IsZero() {
107128
log.Info("attempting to create the packageserver csv")

0 commit comments

Comments
 (0)