Skip to content

Commit 65be851

Browse files
Merge pull request #206 from vbnrh/fix-rolebinding-update
Bug 2279890: Fix createOrUpdate for rolebindings
2 parents 3e03baf + 06ff146 commit 65be851

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

controllers/mirrorpeer_controller.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,19 @@ func (r *MirrorPeerReconciler) createClusterRoleBindingsForSpoke(ctx context.Con
550550
ObjectMeta: metav1.ObjectMeta{
551551
Name: spokeClusterRoleBindingName,
552552
},
553-
Subjects: subjects,
554-
RoleRef: rbacv1.RoleRef{
555-
APIGroup: "rbac.authorization.k8s.io",
556-
Kind: "ClusterRole",
557-
Name: "open-cluster-management:token-exchange:agent",
558-
},
559553
}
560554
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, &spokeRoleBinding, func() error {
555+
spokeRoleBinding.Subjects = subjects
556+
557+
if spokeRoleBinding.CreationTimestamp.IsZero() {
558+
// RoleRef is immutable. So inject it only while creating new object.
559+
spokeRoleBinding.RoleRef = rbacv1.RoleRef{
560+
APIGroup: "rbac.authorization.k8s.io",
561+
Kind: "ClusterRole",
562+
Name: "open-cluster-management:token-exchange:agent",
563+
}
564+
}
565+
561566
return nil
562567
})
563568

0 commit comments

Comments
 (0)