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

Validate ConfigMapRef and SecretRef name #42083

Merged
merged 1 commit into from Apr 3, 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
8 changes: 8 additions & 0 deletions pkg/api/validation/validation.go
Expand Up @@ -1399,6 +1399,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
}
Expand All @@ -1407,6 +1411,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
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/validation/validation_test.go
Expand Up @@ -2316,6 +2316,16 @@ func TestValidateEnvFrom(t *testing.T) {
},
expectedError: "field[0].configMapRef.name: Required value",
},
{
name: "invalid name",
envs: []api.EnvFromSource{
{
ConfigMapRef: &api.ConfigMapEnvSource{
LocalObjectReference: api.LocalObjectReference{Name: "$"}},
},
},
expectedError: "field[0].configMapRef.name: Invalid value",
},
{
name: "invalid prefix",
envs: []api.EnvFromSource{
Expand All @@ -2337,6 +2347,16 @@ func TestValidateEnvFrom(t *testing.T) {
},
expectedError: "field[0].secretRef.name: Required value",
},
{
name: "invalid name",
envs: []api.EnvFromSource{
{
SecretRef: &api.SecretEnvSource{
LocalObjectReference: api.LocalObjectReference{Name: "&"}},
},
},
expectedError: "field[0].secretRef.name: Invalid value",
},
{
name: "invalid prefix",
envs: []api.EnvFromSource{
Expand Down