Skip to content

Commit 538b131

Browse files
authoredJul 31, 2021
don't return an error if the singleton rbac doesn't exist (#2309)
Signed-off-by: Evan <[email protected]>
1 parent 5f6fcd1 commit 538b131

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

Diff for: ‎pkg/controller/operators/olm/operatorgroup.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,14 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
485485
Resources: []string{"namespaces"},
486486
}),
487487
}
488-
if _, err := a.opClient.CreateClusterRole(clusterRole); err != nil {
489-
return err
488+
// TODO: this should do something smarter if the cluster role already exists
489+
if cr, err := a.opClient.CreateClusterRole(clusterRole); err != nil {
490+
// if the CR already exists, but the label is correct, the cache is just behind
491+
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(cr, csv) {
492+
continue
493+
} else {
494+
return err
495+
}
490496
}
491497
a.logger.Debug("created cluster role")
492498
}
@@ -519,8 +525,14 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
519525
Name: r.RoleRef.Name,
520526
},
521527
}
522-
if _, err := a.opClient.CreateClusterRoleBinding(clusterRoleBinding); err != nil {
523-
return err
528+
// TODO: this should do something smarter if the cluster role binding already exists
529+
if crb, err := a.opClient.CreateClusterRoleBinding(clusterRoleBinding); err != nil {
530+
// if the CR already exists, but the label is correct, the cache is just behind
531+
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(crb, csv) {
532+
continue
533+
} else {
534+
return err
535+
}
524536
}
525537
}
526538
}

0 commit comments

Comments
 (0)