Merge pull request #116247 from ardaguclu/skip-hassupport-check-for-list

Skip hasSupport check for List type
This commit is contained in:
Kubernetes Prow Robot 2023-03-07 04:20:24 -08:00 committed by GitHub
commit 1692de5f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -72,6 +72,10 @@ const (
// HasSupport checks if the given gvk supports the query param configured on v // HasSupport checks if the given gvk supports the query param configured on v
func (v *QueryParamVerifier) HasSupport(gvk schema.GroupVersionKind) error { func (v *QueryParamVerifier) HasSupport(gvk schema.GroupVersionKind) error {
if (gvk == schema.GroupVersionKind{Version: "v1", Kind: "List"}) {
return NewParamUnsupportedError(gvk, v.queryParam)
}
oapi, err := v.openAPIGetter.OpenAPISchema() oapi, err := v.openAPIGetter.OpenAPISchema()
if err != nil { if err != nil {
return fmt.Errorf("failed to download openapi: %v", err) return fmt.Errorf("failed to download openapi: %v", err)

View File

@ -69,6 +69,16 @@ func TestSupportsQueryParam(t *testing.T) {
supports: false, supports: false,
queryParam: QueryParamFieldValidation, queryParam: QueryParamFieldValidation,
}, },
{
gvk: schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "List",
},
success: false,
supports: false,
queryParam: QueryParamFieldValidation,
},
} }
for _, test := range tests { for _, test := range tests {
@ -124,6 +134,11 @@ func TestFieldValidationVerifier(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("Random doesn't support fieldValidation, yet no error found") t.Fatalf("Random doesn't support fieldValidation, yet no error found")
} }
err = fieldValidationVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "List"})
if err == nil {
t.Fatalf("List does not support fieldValidation, yet no error found")
}
} }
type EmptyOpenAPI struct{} type EmptyOpenAPI struct{}
@ -159,4 +174,9 @@ func TestFieldValidationVerifierNoOpenAPI(t *testing.T) {
if err == nil { if err == nil {
t.Fatalf("MyCRD doesn't support fieldValidation, yet no error found") t.Fatalf("MyCRD doesn't support fieldValidation, yet no error found")
} }
err = fieldValidationVerifier.HasSupport(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "List"})
if err == nil {
t.Fatalf("List does not support fieldValidation, yet no error found")
}
} }