Skip to content

Commit

Permalink
Fix createOrUpdate for rolebindings
Browse files Browse the repository at this point in the history
This commit fixes issue with mutate fn for controllerutil
createOrUpdate function

Signed-off-by: vbadrina <[email protected]>
  • Loading branch information
vbnrh authored and openshift-cherrypick-robot committed May 15, 2024
1 parent d0cc309 commit 30819db
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions controllers/mirrorpeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,19 @@ func (r *MirrorPeerReconciler) createClusterRoleBindingsForSpoke(ctx context.Con
ObjectMeta: metav1.ObjectMeta{
Name: spokeClusterRoleBindingName,
},
Subjects: subjects,
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: "open-cluster-management:token-exchange:agent",
},
}
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, &spokeRoleBinding, func() error {
spokeRoleBinding.Subjects = subjects

if spokeRoleBinding.CreationTimestamp.IsZero() {
// RoleRef is immutable. So inject it only while creating new object.
spokeRoleBinding.RoleRef = rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: "open-cluster-management:token-exchange:agent",
}
}

return nil
})

Expand Down

0 comments on commit 30819db

Please sign in to comment.