pod spec must validate envFrom
This commit is contained in:
@@ -2706,6 +2706,34 @@ func TestValidateEnv(t *testing.T) {
|
||||
}},
|
||||
expectedError: `[0].valueFrom: Invalid value: "": may not have more than one field specified at a time`,
|
||||
},
|
||||
{
|
||||
name: "valueFrom.secretKeyRef.name invalid",
|
||||
envs: []api.EnvVar{{
|
||||
Name: "abc",
|
||||
ValueFrom: &api.EnvVarSource{
|
||||
SecretKeyRef: &api.SecretKeySelector{
|
||||
LocalObjectReference: api.LocalObjectReference{
|
||||
Name: "$%^&*#",
|
||||
},
|
||||
Key: "a-key",
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "valueFrom.configMapKeyRef.name invalid",
|
||||
envs: []api.EnvVar{{
|
||||
Name: "abc",
|
||||
ValueFrom: &api.EnvVarSource{
|
||||
ConfigMapKeyRef: &api.ConfigMapKeySelector{
|
||||
LocalObjectReference: api.LocalObjectReference{
|
||||
Name: "$%^&*#",
|
||||
},
|
||||
Key: "some-key",
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "missing FieldPath on ObjectFieldSelector",
|
||||
envs: []api.EnvVar{{
|
||||
@@ -2912,6 +2940,26 @@ func TestValidateEnvFrom(t *testing.T) {
|
||||
},
|
||||
expectedError: "field: Invalid value: \"\": may not have more than one field specified at a time",
|
||||
},
|
||||
{
|
||||
name: "invalid secret ref name",
|
||||
envs: []api.EnvFromSource{
|
||||
{
|
||||
SecretRef: &api.SecretEnvSource{
|
||||
LocalObjectReference: api.LocalObjectReference{Name: "$%^&*#"}},
|
||||
},
|
||||
},
|
||||
expectedError: "field[0].secretRef.name: Invalid value: \"$%^&*#\": " + dnsSubdomainLabelErrMsg,
|
||||
},
|
||||
{
|
||||
name: "invalid config ref name",
|
||||
envs: []api.EnvFromSource{
|
||||
{
|
||||
ConfigMapRef: &api.ConfigMapEnvSource{
|
||||
LocalObjectReference: api.LocalObjectReference{Name: "$%^&*#"}},
|
||||
},
|
||||
},
|
||||
expectedError: "field[0].configMapRef.name: Invalid value: \"$%^&*#\": " + dnsSubdomainLabelErrMsg,
|
||||
},
|
||||
}
|
||||
for _, tc := range errorCases {
|
||||
if errs := ValidateEnvFrom(tc.envs, field.NewPath("field")); len(errs) == 0 {
|
||||
@@ -3223,6 +3271,21 @@ func TestValidateContainers(t *testing.T) {
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
TerminationMessagePolicy: "File",
|
||||
},
|
||||
{
|
||||
Name: "env-from-source",
|
||||
Image: "image",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
TerminationMessagePolicy: "File",
|
||||
EnvFrom: []api.EnvFromSource{
|
||||
{
|
||||
ConfigMapRef: &api.ConfigMapEnvSource{
|
||||
LocalObjectReference: api.LocalObjectReference{
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{Name: "abc-1234", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File", SecurityContext: fakeValidSecurityContext(true)},
|
||||
}
|
||||
if errs := validateContainers(successCase, volumes, field.NewPath("field")); len(errs) != 0 {
|
||||
@@ -3452,6 +3515,23 @@ func TestValidateContainers(t *testing.T) {
|
||||
TerminationMessagePolicy: "File",
|
||||
},
|
||||
},
|
||||
"Invalid env from": {
|
||||
{
|
||||
Name: "env-from-source",
|
||||
Image: "image",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
TerminationMessagePolicy: "File",
|
||||
EnvFrom: []api.EnvFromSource{
|
||||
{
|
||||
ConfigMapRef: &api.ConfigMapEnvSource{
|
||||
LocalObjectReference: api.LocalObjectReference{
|
||||
Name: "$%^&*#",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, v := range errorCases {
|
||||
if errs := validateContainers(v, volumes, field.NewPath("field")); len(errs) == 0 {
|
||||
|
Reference in New Issue
Block a user