add validate in create rolebinding

pull/6/head
xilabao 2017-04-28 17:33:30 +08:00
parent 904b020756
commit 0c0a32d870
2 changed files with 2 additions and 2 deletions

View File

@ -132,7 +132,7 @@ func (s ClusterRoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, err
}
for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":")
if len(tokens) != 2 {
if len(tokens) != 2 || tokens[0] == "" || tokens[1] == "" {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")
}
clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{

View File

@ -147,7 +147,7 @@ func (s RoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, error) {
}
for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":")
if len(tokens) != 2 {
if len(tokens) != 2 || tokens[1] == "" {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")
}
roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{