Merge pull request #43509 from xilabao/remove-duplicate-in-create-rolebinding

Automatic merge from submit-queue (batch tested with PRs 42617, 43247, 43509, 43644, 43820)

ignore duplicate resource in create rolebinding
This commit is contained in:
Kubernetes Submit Queue 2017-03-29 16:05:23 -07:00 committed by GitHub
commit 8fc0c708d1
3 changed files with 9 additions and 6 deletions

View File

@ -97,6 +97,7 @@ go_library(
"//vendor:k8s.io/apimachinery/pkg/types", "//vendor:k8s.io/apimachinery/pkg/types",
"//vendor:k8s.io/apimachinery/pkg/util/errors", "//vendor:k8s.io/apimachinery/pkg/util/errors",
"//vendor:k8s.io/apimachinery/pkg/util/intstr", "//vendor:k8s.io/apimachinery/pkg/util/intstr",
"//vendor:k8s.io/apimachinery/pkg/util/sets",
"//vendor:k8s.io/apimachinery/pkg/util/uuid", "//vendor:k8s.io/apimachinery/pkg/util/uuid",
"//vendor:k8s.io/apimachinery/pkg/util/validation", "//vendor:k8s.io/apimachinery/pkg/util/validation",
"//vendor:k8s.io/apimachinery/pkg/util/wait", "//vendor:k8s.io/apimachinery/pkg/util/wait",

View File

@ -22,6 +22,7 @@ import (
"strings" "strings"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/apis/rbac" "k8s.io/kubernetes/pkg/apis/rbac"
) )
@ -115,21 +116,21 @@ func (s ClusterRoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, err
Kind: "ClusterRole", Kind: "ClusterRole",
Name: s.ClusterRole, Name: s.ClusterRole,
} }
for _, user := range s.Users { for _, user := range sets.NewString(s.Users...).List() {
clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{ clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{
Kind: rbac.UserKind, Kind: rbac.UserKind,
APIGroup: rbac.GroupName, APIGroup: rbac.GroupName,
Name: user, Name: user,
}) })
} }
for _, group := range s.Groups { for _, group := range sets.NewString(s.Groups...).List() {
clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{ clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{
Kind: rbac.GroupKind, Kind: rbac.GroupKind,
APIGroup: rbac.GroupName, APIGroup: rbac.GroupName,
Name: group, Name: group,
}) })
} }
for _, sa := range s.ServiceAccounts { for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":") tokens := strings.Split(sa, ":")
if len(tokens) != 2 { if len(tokens) != 2 {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>") return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")

View File

@ -22,6 +22,7 @@ import (
"strings" "strings"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/apis/rbac" "k8s.io/kubernetes/pkg/apis/rbac"
) )
@ -130,21 +131,21 @@ func (s RoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, error) {
} }
} }
for _, user := range s.Users { for _, user := range sets.NewString(s.Users...).List() {
roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{ roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{
Kind: rbac.UserKind, Kind: rbac.UserKind,
APIGroup: rbac.GroupName, APIGroup: rbac.GroupName,
Name: user, Name: user,
}) })
} }
for _, group := range s.Groups { for _, group := range sets.NewString(s.Groups...).List() {
roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{ roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{
Kind: rbac.GroupKind, Kind: rbac.GroupKind,
APIGroup: rbac.GroupName, APIGroup: rbac.GroupName,
Name: group, Name: group,
}) })
} }
for _, sa := range s.ServiceAccounts { for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":") tokens := strings.Split(sa, ":")
if len(tokens) != 2 { if len(tokens) != 2 {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>") return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")