mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +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"))...)
|
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 {
|
if numSources != 0 {
|
||||||
allErrs = append(allErrs, field.Invalid(fldPath, "", "may not be specified when `value` is not empty"))
|
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"))
|
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",
|
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",
|
name: "valueFrom.fieldRef and valueFrom.secretKeyRef specified",
|
||||||
envs: []api.EnvVar{{
|
envs: []api.EnvVar{{
|
||||||
|
Loading…
Reference in New Issue
Block a user