Skip to content

Commit f57955d

Browse files
committed
fix: NewDefaultStorageFactory instead of kubeapiserver.NewStorageFactory
1 parent 1ddfc9f commit f57955d

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

pkg/cmd/server/kubernetes/master/master_config.go

+11-20
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ import (
4444
"k8s.io/kubernetes/pkg/apis/apps"
4545
"k8s.io/kubernetes/pkg/apis/autoscaling"
4646
"k8s.io/kubernetes/pkg/apis/batch"
47+
batchv2alpha1 "k8s.io/kubernetes/pkg/apis/batch/v2alpha1"
4748
"k8s.io/kubernetes/pkg/apis/extensions"
4849
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
4950
kinternalclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
5051
"k8s.io/kubernetes/pkg/cloudprovider"
51-
"k8s.io/kubernetes/pkg/kubeapiserver"
5252
"k8s.io/kubernetes/pkg/master"
5353
"k8s.io/kubernetes/pkg/registry/cachesize"
5454
"k8s.io/kubernetes/pkg/registry/core/endpoint"
@@ -160,40 +160,31 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver
160160
func BuildStorageFactory(masterConfig configapi.MasterConfig, server *kapiserveroptions.ServerRunOptions, enforcedStorageVersions []schema.GroupVersionResource) (*apiserverstorage.DefaultStorageFactory, error) {
161161
resourceEncodingConfig := apiserverstorage.NewDefaultResourceEncodingConfig(kapi.Registry)
162162

163-
// TODO(rebase): the following were without effect at least since 3.5. Remove them?
164-
// resourceEncodingConfig.SetVersionEncoding(kapi.GroupName, schema.GroupVersion{Group: kapi.GroupName, Version: masterConfig.EtcdStorageConfig.KubernetesStorageVersion}, kapi.SchemeGroupVersion)
165-
// resourceEncodingConfig.SetVersionEncoding(extensions.GroupName, schema.GroupVersion{Group: extensions.GroupName, Version: "v1beta1"}, extensions.SchemeGroupVersion)
166-
// resourceEncodingConfig.SetVersionEncoding(batch.GroupName, schema.GroupVersion{Group: batch.GroupName, Version: "v1"}, batch.SchemeGroupVersion)
167-
// resourceEncodingConfig.SetVersionEncoding(autoscaling.GroupName, schema.GroupVersion{Group: autoscaling.GroupName, Version: "v1"}, autoscaling.SchemeGroupVersion)
168-
169163
storageGroupsToEncodingVersion, err := server.StorageSerialization.StorageGroupsToEncodingVersion()
170164
if err != nil {
171165
return nil, err
172166
}
167+
for group, storageEncodingVersion := range storageGroupsToEncodingVersion {
168+
resourceEncodingConfig.SetVersionEncoding(group, storageEncodingVersion, schema.GroupVersion{Group: group, Version: runtime.APIVersionInternal})
169+
}
170+
resourceEncodingConfig.SetVersionEncoding(batch.GroupName, batchv2alpha1.SchemeGroupVersion, batch.SchemeGroupVersion)
171+
172+
// use legacy group name "" for all resources that existed when apigroups were introduced
173+
for _, gvr := range enforcedStorageVersions {
174+
resourceEncodingConfig.SetResourceEncoding(gvr.GroupResource(), schema.GroupVersion{Version: gvr.Version}, schema.GroupVersion{Version: runtime.APIVersionInternal})
175+
}
173176

174-
storageFactory, err := kubeapiserver.NewStorageFactory(
177+
storageFactory := apiserverstorage.NewDefaultStorageFactory(
175178
server.Etcd.StorageConfig,
176179
server.Etcd.DefaultStorageMediaType,
177180
kapi.Codecs,
178181
resourceEncodingConfig,
179-
storageGroupsToEncodingVersion,
180-
// FIXME: this GroupVersionResource override should be configurable
181-
[]schema.GroupVersionResource{batch.Resource("cronjobs").WithVersion("v2alpha1")},
182182
master.DefaultAPIResourceConfigSource(),
183-
server.APIEnablement.RuntimeConfig,
184183
)
185184
if err != nil {
186185
return nil, err
187186
}
188187

189-
// TODO: the following works, but better make single resource overrides possible in BuildDefaultStorageFactory
190-
// instead of being late to the party and patching here:
191-
192-
// use legacy group name "" for all resources that existed when apigroups were introduced
193-
for _, gvr := range enforcedStorageVersions {
194-
resourceEncodingConfig.SetResourceEncoding(gvr.GroupResource(), schema.GroupVersion{Version: gvr.Version}, schema.GroupVersion{Version: runtime.APIVersionInternal})
195-
}
196-
197188
// the order here is important, it defines which version will be used for storage
198189
storageFactory.AddCohabitatingResources(batch.Resource("jobs"), extensions.Resource("jobs"))
199190
storageFactory.AddCohabitatingResources(extensions.Resource("horizontalpodautoscalers"), autoscaling.Resource("horizontalpodautoscalers"))

0 commit comments

Comments
 (0)