mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
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:
commit
70684584be
@ -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
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user