Merge pull request #42083 from fraenkel/validate_name

Automatic merge from submit-queue (batch tested with PRs 42038, 42083)

Validate ConfigMapRef and SecretRef name

fixes #42037

**Release note**:
```release-note
When creating a container using envFrom,
1. validate the name of the ConfigMap in a ConfigMapRef
2. validate the name of the Secret in a SecretRef
```
This commit is contained in:
Kubernetes Submit Queue
2017-04-03 04:07:21 -07:00
committed by GitHub
2 changed files with 28 additions and 0 deletions

View File

@@ -1524,6 +1524,10 @@ func validateConfigMapEnvSource(configMapSource *api.ConfigMapEnvSource, fldPath
allErrs := field.ErrorList{}
if len(configMapSource.Name) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("name"), ""))
} else {
for _, msg := range ValidateConfigMapName(configMapSource.Name, true) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), configMapSource.Name, msg))
}
}
return allErrs
}
@@ -1532,6 +1536,10 @@ func validateSecretEnvSource(secretSource *api.SecretEnvSource, fldPath *field.P
allErrs := field.ErrorList{}
if len(secretSource.Name) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("name"), ""))
} else {
for _, msg := range ValidateSecretName(secretSource.Name, true) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), secretSource.Name, msg))
}
}
return allErrs
}