Unverified Commit 235badbe authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #66512 from jennybuckley/openapi-ignore-prefix

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Skip building openapi for ignored paths alternative to #66286 /kind bug Fixes #66285 ```release-note NONE ```
parents 6fe7f9f4 37c10e2e
......@@ -85,6 +85,8 @@ go_library(
"//vendor/github.com/emicklei/go-restful:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/builder:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/util:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/util/proto:go_default_library",
],
)
......
......@@ -41,6 +41,8 @@ import (
genericfilters "k8s.io/apiserver/pkg/server/filters"
utilopenapi "k8s.io/apiserver/pkg/util/openapi"
openapibuilder "k8s.io/kube-openapi/pkg/builder"
openapiutil "k8s.io/kube-openapi/pkg/util"
openapiproto "k8s.io/kube-openapi/pkg/util/proto"
)
const (
......@@ -498,15 +500,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
if a.group.MetaGroupVersion != nil {
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
}
if a.group.OpenAPIConfig != nil {
openAPIDefinitions, err := openapibuilder.BuildOpenAPIDefinitionsForResource(defaultVersionedObject, a.group.OpenAPIConfig)
if err != nil {
return nil, fmt.Errorf("unable to build openapi definitions for %v: %v", fqKindToRegister, err)
}
reqScope.OpenAPISchema, err = utilopenapi.ToProtoSchema(openAPIDefinitions, fqKindToRegister)
if err != nil {
return nil, fmt.Errorf("unable to get openapi schema for %v: %v", fqKindToRegister, err)
}
reqScope.OpenAPISchema, err = a.getOpenAPISchema(ws.RootPath(), resource, fqKindToRegister, defaultVersionedObject)
if err != nil {
return nil, fmt.Errorf("unable to get openapi schema for %v: %v", fqKindToRegister, err)
}
for _, action := range actions {
producedObject := storageMeta.ProducesObject(action.Verb)
......@@ -852,6 +848,24 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
return &apiResource, nil
}
// getOpenAPISchema builds the openapi schema for a single resource model to be given to each handler. It will
// return nil if the apiserver doesn't have openapi enabled, or if the specific path should be ignored by openapi.
func (a *APIInstaller) getOpenAPISchema(rootPath, resource string, kind schema.GroupVersionKind, sampleObject interface{}) (openapiproto.Schema, error) {
path := gpath.Join(rootPath, resource)
if a.group.OpenAPIConfig == nil {
return nil, nil
}
pathsToIgnore := openapiutil.NewTrie(a.group.OpenAPIConfig.IgnorePrefixes)
if pathsToIgnore.HasPrefix(path) {
return nil, nil
}
openAPIDefinitions, err := openapibuilder.BuildOpenAPIDefinitionsForResource(sampleObject, a.group.OpenAPIConfig)
if err != nil {
return nil, err
}
return utilopenapi.ToProtoSchema(openAPIDefinitions, kind)
}
// indirectArbitraryPointer returns *ptrToObject for an arbitrary pointer
func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
return reflect.Indirect(reflect.ValueOf(ptrToObject)).Interface()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment