mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
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 ```
This commit is contained in:
commit
235badbe5a
@ -85,6 +85,8 @@ go_library(
|
|||||||
"//vendor/github.com/emicklei/go-restful:go_default_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/builder:go_default_library",
|
||||||
"//vendor/k8s.io/kube-openapi/pkg/common: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"
|
genericfilters "k8s.io/apiserver/pkg/server/filters"
|
||||||
utilopenapi "k8s.io/apiserver/pkg/util/openapi"
|
utilopenapi "k8s.io/apiserver/pkg/util/openapi"
|
||||||
openapibuilder "k8s.io/kube-openapi/pkg/builder"
|
openapibuilder "k8s.io/kube-openapi/pkg/builder"
|
||||||
|
openapiutil "k8s.io/kube-openapi/pkg/util"
|
||||||
|
openapiproto "k8s.io/kube-openapi/pkg/util/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -498,15 +500,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
if a.group.MetaGroupVersion != nil {
|
if a.group.MetaGroupVersion != nil {
|
||||||
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
||||||
}
|
}
|
||||||
if a.group.OpenAPIConfig != nil {
|
reqScope.OpenAPISchema, err = a.getOpenAPISchema(ws.RootPath(), resource, fqKindToRegister, defaultVersionedObject)
|
||||||
openAPIDefinitions, err := openapibuilder.BuildOpenAPIDefinitionsForResource(defaultVersionedObject, a.group.OpenAPIConfig)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("unable to get openapi schema for %v: %v", fqKindToRegister, err)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
producedObject := storageMeta.ProducesObject(action.Verb)
|
producedObject := storageMeta.ProducesObject(action.Verb)
|
||||||
@ -852,6 +848,24 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
return &apiResource, nil
|
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
|
// indirectArbitraryPointer returns *ptrToObject for an arbitrary pointer
|
||||||
func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
|
func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
|
||||||
return reflect.Indirect(reflect.ValueOf(ptrToObject)).Interface()
|
return reflect.Indirect(reflect.ValueOf(ptrToObject)).Interface()
|
||||||
|
Loading…
Reference in New Issue
Block a user