Throw error if OpenAPIV3 config is not provided
it is required for Server-SIde-Apply to function correctly (SSA is based on OpenAPI schemas) Kubernetes-commit: 302daa889c5ddb9c862cd0101b94071e42a3081d
This commit is contained in:
parent
a88d792173
commit
3783e4af68
|
@ -674,10 +674,6 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
||||
}
|
||||
|
||||
// Use TypeConverter's nil-ness as a proxy for whether SSA/OpenAPI is enabled
|
||||
// This should be removed in the future and made unconditional
|
||||
// https://github.com/kubernetes/kubernetes/pull/114998
|
||||
if a.group.TypeConverter != nil {
|
||||
var resetFields map[fieldpath.APIVersion]*fieldpath.Set
|
||||
if resetFieldsStrategy, isResetFieldsStrategy := storage.(rest.ResetFieldsStrategy); isResetFieldsStrategy {
|
||||
resetFields = resetFieldsStrategy.GetResetFields()
|
||||
|
@ -696,7 +692,6 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to create field manager: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, action := range actions {
|
||||
producedObject := storageMeta.ProducesObject(action.Verb)
|
||||
|
|
|
@ -18,6 +18,7 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
gpath "path"
|
||||
|
@ -736,16 +737,7 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}, shutdow
|
|||
}
|
||||
|
||||
// installAPIResources is a private method for installing the REST storage backing each api groupversionresource
|
||||
func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *APIGroupInfo, openAPIModels map[string]*spec.Schema) error {
|
||||
var typeConverter managedfields.TypeConverter
|
||||
|
||||
if len(openAPIModels) > 0 {
|
||||
var err error
|
||||
typeConverter, err = managedfields.NewTypeConverter(openAPIModels, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *APIGroupInfo, typeConverter managedfields.TypeConverter) error {
|
||||
var resourceInfos []*storageversion.ResourceInfo
|
||||
for _, groupVersion := range apiGroupInfo.PrioritizedVersions {
|
||||
if len(apiGroupInfo.VersionedResourcesStorageMap[groupVersion.Version]) == 0 {
|
||||
|
@ -953,13 +945,13 @@ func NewDefaultAPIGroupInfo(group string, scheme *runtime.Scheme, parameterCodec
|
|||
}
|
||||
|
||||
// getOpenAPIModels is a private method for getting the OpenAPI models
|
||||
func (s *GenericAPIServer) getOpenAPIModels(apiPrefix string, apiGroupInfos ...*APIGroupInfo) (map[string]*spec.Schema, error) {
|
||||
func (s *GenericAPIServer) getOpenAPIModels(apiPrefix string, apiGroupInfos ...*APIGroupInfo) (managedfields.TypeConverter, error) {
|
||||
if s.openAPIV3Config == nil {
|
||||
//!TODO: A future work should add a requirement that
|
||||
// OpenAPIV3 config is required. May require some refactoring of tests.
|
||||
return nil, nil
|
||||
// SSA is GA and requires OpenAPI config to be set
|
||||
// to create models.
|
||||
return nil, errors.New("OpenAPIV3 config must not be nil")
|
||||
}
|
||||
pathsToIgnore := openapiutil.NewTrie(s.openAPIConfig.IgnorePrefixes)
|
||||
pathsToIgnore := openapiutil.NewTrie(s.openAPIV3Config.IgnorePrefixes)
|
||||
resourceNames := make([]string, 0)
|
||||
for _, apiGroupInfo := range apiGroupInfos {
|
||||
groupResources, err := getResourceNamesForGroup(apiPrefix, apiGroupInfo, pathsToIgnore)
|
||||
|
@ -977,7 +969,13 @@ func (s *GenericAPIServer) getOpenAPIModels(apiPrefix string, apiGroupInfos ...*
|
|||
for _, apiGroupInfo := range apiGroupInfos {
|
||||
apiGroupInfo.StaticOpenAPISpec = openAPISpec
|
||||
}
|
||||
return openAPISpec, nil
|
||||
|
||||
typeConverter, err := managedfields.NewTypeConverter(openAPISpec, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typeConverter, nil
|
||||
}
|
||||
|
||||
// getResourceNamesForGroup is a private method for getting the canonical names for each resource to build in an api group
|
||||
|
|
Loading…
Reference in New Issue