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,28 +674,23 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||||
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use TypeConverter's nil-ness as a proxy for whether SSA/OpenAPI is enabled
|
var resetFields map[fieldpath.APIVersion]*fieldpath.Set
|
||||||
// This should be removed in the future and made unconditional
|
if resetFieldsStrategy, isResetFieldsStrategy := storage.(rest.ResetFieldsStrategy); isResetFieldsStrategy {
|
||||||
// https://github.com/kubernetes/kubernetes/pull/114998
|
resetFields = resetFieldsStrategy.GetResetFields()
|
||||||
if a.group.TypeConverter != nil {
|
}
|
||||||
var resetFields map[fieldpath.APIVersion]*fieldpath.Set
|
|
||||||
if resetFieldsStrategy, isResetFieldsStrategy := storage.(rest.ResetFieldsStrategy); isResetFieldsStrategy {
|
|
||||||
resetFields = resetFieldsStrategy.GetResetFields()
|
|
||||||
}
|
|
||||||
|
|
||||||
reqScope.FieldManager, err = managedfields.NewDefaultFieldManager(
|
reqScope.FieldManager, err = managedfields.NewDefaultFieldManager(
|
||||||
a.group.TypeConverter,
|
a.group.TypeConverter,
|
||||||
a.group.UnsafeConvertor,
|
a.group.UnsafeConvertor,
|
||||||
a.group.Defaulter,
|
a.group.Defaulter,
|
||||||
a.group.Creater,
|
a.group.Creater,
|
||||||
fqKindToRegister,
|
fqKindToRegister,
|
||||||
reqScope.HubGroupVersion,
|
reqScope.HubGroupVersion,
|
||||||
subresource,
|
subresource,
|
||||||
resetFields,
|
resetFields,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to create field manager: %v", err)
|
return nil, nil, fmt.Errorf("failed to create field manager: %v", err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
|
|
|
@ -18,6 +18,7 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
gpath "path"
|
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
|
// 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 {
|
func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *APIGroupInfo, typeConverter managedfields.TypeConverter) error {
|
||||||
var typeConverter managedfields.TypeConverter
|
|
||||||
|
|
||||||
if len(openAPIModels) > 0 {
|
|
||||||
var err error
|
|
||||||
typeConverter, err = managedfields.NewTypeConverter(openAPIModels, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var resourceInfos []*storageversion.ResourceInfo
|
var resourceInfos []*storageversion.ResourceInfo
|
||||||
for _, groupVersion := range apiGroupInfo.PrioritizedVersions {
|
for _, groupVersion := range apiGroupInfo.PrioritizedVersions {
|
||||||
if len(apiGroupInfo.VersionedResourcesStorageMap[groupVersion.Version]) == 0 {
|
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
|
// 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 {
|
if s.openAPIV3Config == nil {
|
||||||
//!TODO: A future work should add a requirement that
|
// SSA is GA and requires OpenAPI config to be set
|
||||||
// OpenAPIV3 config is required. May require some refactoring of tests.
|
// to create models.
|
||||||
return nil, nil
|
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)
|
resourceNames := make([]string, 0)
|
||||||
for _, apiGroupInfo := range apiGroupInfos {
|
for _, apiGroupInfo := range apiGroupInfos {
|
||||||
groupResources, err := getResourceNamesForGroup(apiPrefix, apiGroupInfo, pathsToIgnore)
|
groupResources, err := getResourceNamesForGroup(apiPrefix, apiGroupInfo, pathsToIgnore)
|
||||||
|
@ -977,7 +969,13 @@ func (s *GenericAPIServer) getOpenAPIModels(apiPrefix string, apiGroupInfos ...*
|
||||||
for _, apiGroupInfo := range apiGroupInfos {
|
for _, apiGroupInfo := range apiGroupInfos {
|
||||||
apiGroupInfo.StaticOpenAPISpec = openAPISpec
|
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
|
// getResourceNamesForGroup is a private method for getting the canonical names for each resource to build in an api group
|
||||||
|
|
Loading…
Reference in New Issue