diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 397acff75a4..56143796bf7 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -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 } diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index f131cc16cd7..7ce6a6241c7 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -2415,6 +2415,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{ @@ -2436,6 +2446,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{