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

[Federation] Uniquify the ClusterRole and ClusterRoleBinding names created by kubefed join #46376

Merged
merged 1 commit into from
May 25, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion federation/pkg/kubefed/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func createServiceAccount(clusterClientset internalclientset.Interface, namespac
// service account identified by saName to access all resources in all namespaces
// in the cluster associated with clusterClientset.
func createClusterRoleBinding(clusterClientset internalclientset.Interface, saName, namespace, federationName, joiningClusterName string, dryRun bool) (*rbac.ClusterRoleBinding, error) {
roleName := util.ClusterRoleName(saName)
roleName := util.ClusterRoleName(federationName, saName)
role := &rbac.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: roleName,
Expand Down
4 changes: 2 additions & 2 deletions federation/pkg/kubefed/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func fakeJoinTargetClusterFactory(clusterName, clusterCtx, dnsProvider, tmpDirPa
},
}

roleName := util.ClusterRoleName(saName)
roleName := util.ClusterRoleName(testFederationName, saName)
clusterRole := rbacv1beta1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: roleName,
Expand Down Expand Up @@ -595,7 +595,7 @@ func fakeCluster(clusterName, secretName, server string, isRBACAPIAvailable bool
saName := serviceAccountName(clusterName)
annotations := map[string]string{
kubectl.ServiceAccountNameAnnotation: saName,
kubectl.ClusterRoleNameAnnotation: util.ClusterRoleName(saName),
kubectl.ClusterRoleNameAnnotation: util.ClusterRoleName(testFederationName, saName),
}
cluster.ObjectMeta.SetAnnotations(annotations)
}
Expand Down
4 changes: 2 additions & 2 deletions federation/pkg/kubefed/unjoin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func fakeUnjoinHostFactory(clusterName string) cmdutil.Factory {
return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &status)}, nil
case strings.HasPrefix(p, clusterRoleBindingPrefix) && m == http.MethodDelete:
got := strings.TrimPrefix(p, clusterRoleBindingPrefix)
want := util.ClusterRoleName(serviceAccountName(clusterName))
want := util.ClusterRoleName(testFederationName, serviceAccountName(clusterName))
if got != want {
return nil, errors.NewNotFound(api.Resource("clusterrolebindings"), got)
}
Expand All @@ -286,7 +286,7 @@ func fakeUnjoinHostFactory(clusterName string) cmdutil.Factory {
return &http.Response{StatusCode: http.StatusOK, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &status)}, nil
case strings.HasPrefix(p, clusterRolePrefix) && m == http.MethodDelete:
got := strings.TrimPrefix(p, clusterRolePrefix)
want := util.ClusterRoleName(serviceAccountName(clusterName))
want := util.ClusterRoleName(testFederationName, serviceAccountName(clusterName))
if got != want {
return nil, errors.NewNotFound(api.Resource("clusterroles"), got)
}
Expand Down
4 changes: 2 additions & 2 deletions federation/pkg/kubefed/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,6 @@ func ClusterServiceAccountName(joiningClusterName, hostContext string) string {
// ClusterRoleName returns the name of a ClusterRole and its associated
// ClusterRoleBinding that are used to allow the service account to
// access necessary resources on the cluster.
func ClusterRoleName(serviceAccountName string) string {
return fmt.Sprintf("federation-controller-manager:%s", serviceAccountName)
func ClusterRoleName(federationName, serviceAccountName string) string {
return fmt.Sprintf("federation-controller-manager:%s-%s", federationName, serviceAccountName)
}