Skip to content

don't return an error if the singleton rbac doesn't exist #2309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/controller/operators/olm/operatorgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,14 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
Resources: []string{"namespaces"},
}),
}
if _, err := a.opClient.CreateClusterRole(clusterRole); err != nil {
return err
// 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) {
continue
} else {
return err
}
Comment on lines +491 to +495
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(cr, csv) {
continue
} else {
return err
}
if k8serrors.IsAlreadyExists(err) && ownerutil.IsOwnedByLabel(cr, csv) {
continue
}
return err

}
a.logger.Debug("created cluster role")
}
Expand Down Expand Up @@ -519,8 +525,14 @@ func (a *Operator) ensureSingletonRBAC(operatorNamespace string, csv *v1alpha1.C
Name: r.RoleRef.Name,
},
}
if _, err := a.opClient.CreateClusterRoleBinding(clusterRoleBinding); err != nil {
return err
// 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) {
continue
} else {
return err
}
}
}
}
Expand Down