Skip to content

Commit f2adb2d

Browse files
committed
pkg/controller: Fix panic when creating cluster-scoped RBAC in OG controller
Fixes [operator-framework#2091](operator-framework#2091). This is a follow-up to [operator-framework#2309](operator-framework#2309) that attempted to fix the original issue. When checking whether the ClusterRole/ClusterRoleBinding resources already exist, we're also checking whether the existing labels are owned by the CSV we're currently handling. When accessing the "cr" or "crb" variables that the Create calls output, a panic is produced as we're attempting to access the meta.Labels key from those resources, except those resources themselves are nil. Update the check to verify that the cr/crb variables are not nil before attempting to access those object's labels. The testing fake client may need to be updated in the future to handle returning these resources properly. Signed-off-by: timflannagan <[email protected]>
1 parent 11f1d0c commit f2adb2d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pkg/controller/operators/olm/operatorgroup.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,10 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
533533
// TODO: this should do something smarter if the cluster role already exists
534534
if cr, err := a.opClient.CreateClusterRole(clusterRole); err != nil {
535535
// if the CR already exists, but the label is correct, the cache is just behind
536-
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(cr, csv) {
536+
if k8serrors.IsAlreadyExists(err) && cr != nil && ownerutil.IsOwnedByLabel(cr, csv) {
537537
continue
538-
} else {
539-
return err
540538
}
539+
return err
541540
}
542541
a.logger.Debug("created cluster role")
543542
}
@@ -572,12 +571,11 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
572571
}
573572
// TODO: this should do something smarter if the cluster role binding already exists
574573
if crb, err := a.opClient.CreateClusterRoleBinding(clusterRoleBinding); err != nil {
575-
// if the CR already exists, but the label is correct, the cache is just behind
576-
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(crb, csv) {
574+
// if the CRB already exists, but the label is correct, the cache is just behind
575+
if k8serrors.IsAlreadyExists(err) && crb != nil && ownerutil.IsOwnedByLabel(crb, csv) {
577576
continue
578-
} else {
579-
return err
580577
}
578+
return err
581579
}
582580
}
583581
}

0 commit comments

Comments
 (0)