Skip to content
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

Bug 1691546: fix(catalog): do not add owner references to clusterroles or crbs #900

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
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
19 changes: 4 additions & 15 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,16 +1147,11 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
}

// Update UIDs on all CSV OwnerReferences
updated, err := o.getUpdatedOwnerReferences(cr.OwnerReferences, plan.Namespace)
if err != nil {
return errorwrap.Wrapf(err, "error generating ownerrefs for clusterrole %s", cr.GetName())
}
cr.OwnerReferences = updated

// Attempt to create the ClusterRole.
_, err = o.opClient.KubernetesInterface().RbacV1().ClusterRoles().Create(&cr)
if k8serrors.IsAlreadyExists(err) {
// if we're updating, point owner to the newest csv
cr.Labels[ownerutil.OwnerKey] = step.Resolving
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: how is this label ownerutil.OwnerKey used?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a label that points to the owner for cases where we can't use real ownerrefs

_, err = o.opClient.UpdateClusterRole(&cr)
if err != nil {
return errorwrap.Wrapf(err, "error updating clusterrole %s", cr.GetName())
Expand All @@ -1177,17 +1172,11 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
}

// Update UIDs on all CSV OwnerReferences
updated, err := o.getUpdatedOwnerReferences(rb.OwnerReferences, plan.Namespace)
if err != nil {
return errorwrap.Wrapf(err, "error generating ownerrefs for clusterrolebinding %s", rb.GetName())
}
rb.OwnerReferences = updated

// Attempt to create the ClusterRoleBinding.
_, err = o.opClient.KubernetesInterface().RbacV1().ClusterRoleBindings().Create(&rb)
if k8serrors.IsAlreadyExists(err) {
rb.SetNamespace(plan.Namespace)
jpeeler marked this conversation as resolved.
Show resolved Hide resolved
// if we're updating, point owner to the newest csv
rb.Labels[ownerutil.OwnerKey] = step.Resolving
_, err = o.opClient.UpdateClusterRoleBinding(&rb)
if err != nil {
return errorwrap.Wrapf(err, "error updating clusterrolebinding %s", rb.GetName())
Expand Down
13 changes: 5 additions & 8 deletions pkg/controller/registry/resolver/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ func RBACForClusterServiceVersion(csv *v1alpha1.ClusterServiceVersion) (map[stri
if _, ok := permissions[permission.ServiceAccountName]; !ok {
serviceAccount := &corev1.ServiceAccount{}
serviceAccount.SetName(permission.ServiceAccountName)
ownerutil.AddNonBlockingOwner(serviceAccount, csv)

permissions[permission.ServiceAccountName] = NewOperatorPermissions(serviceAccount)
}

// Create ClusterRole
role := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: generateName(csv.GetName()),
OwnerReferences: []metav1.OwnerReference{ownerutil.NonBlockingOwner(csv)},
Labels: ownerutil.OwnerLabel(csv, v1alpha1.ClusterServiceVersionKind),
Name: generateName(csv.GetName()),
Labels: ownerutil.OwnerLabel(csv, v1alpha1.ClusterServiceVersionKind),
},
Rules: permission.Rules,
}
Expand All @@ -137,10 +135,9 @@ func RBACForClusterServiceVersion(csv *v1alpha1.ClusterServiceVersion) (map[stri
// Create ClusterRoleBinding
roleBinding := &rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: generateName(fmt.Sprintf("%s-%s", role.GetName(), permission.ServiceAccountName)),
Namespace: csv.GetNamespace(),
OwnerReferences: []metav1.OwnerReference{ownerutil.NonBlockingOwner(csv)},
Labels: ownerutil.OwnerLabel(csv, v1alpha1.ClusterServiceVersionKind),
Name: generateName(fmt.Sprintf("%s-%s", role.GetName(), permission.ServiceAccountName)),
Namespace: csv.GetNamespace(),
Labels: ownerutil.OwnerLabel(csv, v1alpha1.ClusterServiceVersionKind),
},
RoleRef: rbacv1.RoleRef{
Kind: "ClusterRole",
Expand Down