Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit 66885d2

Browse files
committed
[Federation] Uniquify the ClusterRole and ClusterRoleBinding names created by .
1 parent b09a67e commit 66885d2

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

pkg/kubefed/join.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ func createServiceAccount(clusterClientset internalclientset.Interface, namespac
593593
// service account identified by saName to access all resources in all namespaces
594594
// in the cluster associated with clusterClientset.
595595
func createClusterRoleBinding(clusterClientset internalclientset.Interface, saName, namespace, federationName, joiningClusterName string, dryRun bool) (*rbac.ClusterRoleBinding, error) {
596-
roleName := util.ClusterRoleName(saName)
596+
roleName := util.ClusterRoleName(federationName, saName)
597597
role := &rbac.ClusterRole{
598598
ObjectMeta: metav1.ObjectMeta{
599599
Name: roleName,

pkg/kubefed/join_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func fakeJoinTargetClusterFactory(clusterName, clusterCtx, dnsProvider, tmpDirPa
475475
},
476476
}
477477

478-
roleName := util.ClusterRoleName(saName)
478+
roleName := util.ClusterRoleName(testFederationName, saName)
479479
clusterRole := rbacv1beta1.ClusterRole{
480480
ObjectMeta: metav1.ObjectMeta{
481481
Name: roleName,
@@ -595,7 +595,7 @@ func fakeCluster(clusterName, secretName, server string, isRBACAPIAvailable bool
595595
saName := serviceAccountName(clusterName)
596596
annotations := map[string]string{
597597
kubectl.ServiceAccountNameAnnotation: saName,
598-
kubectl.ClusterRoleNameAnnotation: util.ClusterRoleName(saName),
598+
kubectl.ClusterRoleNameAnnotation: util.ClusterRoleName(testFederationName, saName),
599599
}
600600
cluster.ObjectMeta.SetAnnotations(annotations)
601601
}

pkg/kubefed/unjoin_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func fakeUnjoinHostFactory(clusterName string) cmdutil.Factory {
275275
return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &status)}, nil
276276
case strings.HasPrefix(p, clusterRoleBindingPrefix) && m == http.MethodDelete:
277277
got := strings.TrimPrefix(p, clusterRoleBindingPrefix)
278-
want := util.ClusterRoleName(serviceAccountName(clusterName))
278+
want := util.ClusterRoleName(testFederationName, serviceAccountName(clusterName))
279279
if got != want {
280280
return nil, errors.NewNotFound(api.Resource("clusterrolebindings"), got)
281281
}
@@ -286,7 +286,7 @@ func fakeUnjoinHostFactory(clusterName string) cmdutil.Factory {
286286
return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &status)}, nil
287287
case strings.HasPrefix(p, clusterRolePrefix) && m == http.MethodDelete:
288288
got := strings.TrimPrefix(p, clusterRolePrefix)
289-
want := util.ClusterRoleName(serviceAccountName(clusterName))
289+
want := util.ClusterRoleName(testFederationName, serviceAccountName(clusterName))
290290
if got != want {
291291
return nil, errors.NewNotFound(api.Resource("clusterroles"), got)
292292
}

pkg/kubefed/util/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,6 @@ func ClusterServiceAccountName(joiningClusterName, hostContext string) string {
302302
// ClusterRoleName returns the name of a ClusterRole and its associated
303303
// ClusterRoleBinding that are used to allow the service account to
304304
// access necessary resources on the cluster.
305-
func ClusterRoleName(serviceAccountName string) string {
306-
return fmt.Sprintf("federation-controller-manager:%s", serviceAccountName)
305+
func ClusterRoleName(federationName, serviceAccountName string) string {
306+
return fmt.Sprintf("federation-controller-manager:%s-%s", federationName, serviceAccountName)
307307
}

0 commit comments

Comments
 (0)