mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Improved validation error message when env.valueFrom contains no (or misspelled) ref
This commit is contained in:
parent
c41c24fbf3
commit
d8ec7181b4
@ -1350,11 +1350,13 @@ func validateEnvVarValueFrom(ev api.EnvVar, fldPath *field.Path) field.ErrorList
|
||||
allErrs = append(allErrs, validateSecretKeySelector(ev.ValueFrom.SecretKeyRef, fldPath.Child("secretKeyRef"))...)
|
||||
}
|
||||
|
||||
if len(ev.Value) != 0 {
|
||||
if numSources == 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, "", "must specify one of: `fieldRef`, `resourceFieldRef`, `configMapKeyRef` or `secretKeyRef`"))
|
||||
} else if len(ev.Value) != 0 {
|
||||
if numSources != 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, "", "may not be specified when `value` is not empty"))
|
||||
}
|
||||
} else if numSources != 1 {
|
||||
} else if numSources > 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, "", "may not have more than one field specified at a time"))
|
||||
}
|
||||
|
||||
|
@ -2446,6 +2446,15 @@ func TestValidateEnv(t *testing.T) {
|
||||
}},
|
||||
expectedError: "[0].valueFrom: Invalid value: \"\": may not be specified when `value` is not empty",
|
||||
},
|
||||
{
|
||||
name: "valueFrom without a source",
|
||||
envs: []api.EnvVar{{
|
||||
Name: "abc",
|
||||
ValueFrom: &api.EnvVarSource{
|
||||
},
|
||||
}},
|
||||
expectedError: "[0].valueFrom: Invalid value: \"\": must specify one of: `fieldRef`, `resourceFieldRef`, `configMapKeyRef` or `secretKeyRef`",
|
||||
},
|
||||
{
|
||||
name: "valueFrom.fieldRef and valueFrom.secretKeyRef specified",
|
||||
envs: []api.EnvVar{{
|
||||
|
Loading…
Reference in New Issue
Block a user