Skip to content

Commit

Permalink
pkg/controller: Fix panic when creating cluster-scoped RBAC in OG con…
Browse files Browse the repository at this point in the history
…troller

Fixes [#2091](#2091).

This is a follow-up to [#2309](#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 <timflannagan@gmail.com>
  • Loading branch information
timflannagan committed Sep 14, 2021
1 parent 11f1d0c commit f2adb2d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pkg/controller/operators/olm/operatorgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,10 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
// TODO: this should do something smarter if the cluster role already exists
if cr, err := a.opClient.CreateClusterRole(clusterRole); err != nil {
// if the CR already exists, but the label is correct, the cache is just behind
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(cr, csv) {
if k8serrors.IsAlreadyExists(err) && cr != nil && ownerutil.IsOwnedByLabel(cr, csv) {
continue
} else {
return err
}
return err
}
a.logger.Debug("created cluster role")
}
Expand Down Expand Up @@ -572,12 +571,11 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
}
// TODO: this should do something smarter if the cluster role binding already exists
if crb, err := a.opClient.CreateClusterRoleBinding(clusterRoleBinding); err != nil {
// if the CR already exists, but the label is correct, the cache is just behind
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(crb, csv) {
// if the CRB already exists, but the label is correct, the cache is just behind
if k8serrors.IsAlreadyExists(err) && crb != nil && ownerutil.IsOwnedByLabel(crb, csv) {
continue
} else {
return err
}
return err
}
}
}
Expand Down

0 comments on commit f2adb2d

Please sign in to comment.