Check multiple entries in the validation. (#367)

This is a list and we check all of them to be conformant, but return only first error,
which is a departure from what we do in most of the serving.
This commit is contained in:
Victor Agababov 2020-10-21 16:41:32 -07:00 committed by GitHub
parent 9d8ef6a9d2
commit 7646d730f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -30,7 +30,7 @@ func (rt *Image) Validate(ctx context.Context) *apis.FieldError {
return rt.Spec.Validate(ctx).ViaField("spec")
}
func (rs *ImageSpec) Validate(ctx context.Context) *apis.FieldError {
func (rs *ImageSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
if rs.Image == "" {
return apis.ErrMissingField("image")
}
@ -39,8 +39,8 @@ func (rs *ImageSpec) Validate(ctx context.Context) *apis.FieldError {
// https://github.com/google/go-containerregistry/blob/2f3e3e1/pkg/name/ref.go#L41
for index, ips := range rs.ImagePullSecrets {
if equality.Semantic.DeepEqual(ips, corev1.LocalObjectReference{}) {
return apis.ErrMissingField(fmt.Sprintf("imagePullSecrets[%d].name", index))
errs = errs.Also(apis.ErrMissingField(fmt.Sprintf("imagePullSecrets[%d].name", index)))
}
}
return nil
return errs
}

View File

@ -51,6 +51,18 @@ func TestImageValidation(t *testing.T) {
},
},
want: apis.ErrMissingField("spec.imagePullSecrets[0].name"),
}, {
name: "nested multiple spec errors",
r: &Image{
Spec: ImageSpec{
Image: "busybox",
ImagePullSecrets: []corev1.LocalObjectReference{{
Name: "frankie",
}, {}, {}},
},
},
want: apis.ErrMissingField("spec.imagePullSecrets[1].name").
Also(apis.ErrMissingField("spec.imagePullSecrets[2].name")),
}}
for _, test := range tests {