forbid unnamed context

Kubernetes-commit: 792a2299362ebadc9ca68c72347884330db23b2a
This commit is contained in:
Di Xu
2017-12-04 14:39:05 +08:00
committed by Kubernetes Publisher
parent 18ec62fe90
commit 370f3b346b
2 changed files with 33 additions and 0 deletions

View File

@@ -253,6 +253,10 @@ func validateAuthInfo(authInfoName string, authInfo clientcmdapi.AuthInfo) []err
func validateContext(contextName string, context clientcmdapi.Context, config clientcmdapi.Config) []error {
validationErrors := make([]error, 0)
if len(contextName) == 0 {
validationErrors = append(validationErrors, fmt.Errorf("empty context name for %#v is not allowed", context))
}
if len(context.AuthInfo) == 0 {
validationErrors = append(validationErrors, fmt.Errorf("user was not specified for context %q", contextName))
} else if _, exists := config.AuthInfos[context.AuthInfo]; !exists {