mirror of https://github.com/k3s-io/k3s
Remove the --storage-versions flag from kube-apiserver.
The storage version now is solely decided by the scheme.PrioritizedVersionsForGroup(). For cohabitating resources, the storage version will be that of the overriding group as returned by storageFactory.getStorageGroupResource().pull/564/head
parent
cc45621baf
commit
1281243860
|
@ -47,7 +47,6 @@ type ServerRunOptions struct {
|
|||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
||||
CloudProvider *kubeoptions.CloudProviderOptions
|
||||
StorageSerialization *kubeoptions.StorageSerializationOptions
|
||||
APIEnablement *genericoptions.APIEnablementOptions
|
||||
|
||||
AllowPrivileged bool
|
||||
|
@ -87,7 +86,6 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
||||
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||
StorageSerialization: kubeoptions.NewStorageSerializationOptions(),
|
||||
APIEnablement: genericoptions.NewAPIEnablementOptions(),
|
||||
|
||||
EnableLogsHandler: true,
|
||||
|
@ -135,7 +133,6 @@ func (s *ServerRunOptions) Flags() (fss apiserverflag.NamedFlagSets) {
|
|||
s.Authentication.AddFlags(fss.FlagSet("authentication"))
|
||||
s.Authorization.AddFlags(fss.FlagSet("authorization"))
|
||||
s.CloudProvider.AddFlags(fss.FlagSet("cloud provider"))
|
||||
s.StorageSerialization.AddFlags(fss.FlagSet("storage"))
|
||||
s.APIEnablement.AddFlags(fss.FlagSet("api enablement"))
|
||||
s.Admission.AddFlags(fss.FlagSet("admission"))
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
auditdynamic "k8s.io/apiserver/plugin/pkg/audit/dynamic"
|
||||
audittruncate "k8s.io/apiserver/plugin/pkg/audit/truncate"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
kapi "k8s.io/kubernetes/pkg/apis/core"
|
||||
kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
|
||||
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
||||
|
@ -287,10 +286,6 @@ func TestAddFlags(t *testing.T) {
|
|||
CloudConfigFile: "/cloud-config",
|
||||
CloudProvider: "azure",
|
||||
},
|
||||
StorageSerialization: &kubeoptions.StorageSerializationOptions{
|
||||
StorageVersions: kubeoptions.ToPreferredVersionString(legacyscheme.Scheme.PreferredVersionAllGroups()),
|
||||
DefaultStorageVersions: kubeoptions.ToPreferredVersionString(legacyscheme.Scheme.PreferredVersionAllGroups()),
|
||||
},
|
||||
APIEnablement: &apiserveroptions.APIEnablementOptions{
|
||||
RuntimeConfig: utilflag.ConfigurationMap{},
|
||||
},
|
||||
|
|
|
@ -415,7 +415,7 @@ func buildGenericConfig(
|
|||
|
||||
storageFactoryConfig := kubeapiserver.NewStorageFactoryConfig()
|
||||
storageFactoryConfig.ApiResourceConfig = genericConfig.MergedResourceConfig
|
||||
completedStorageFactoryConfig, err := storageFactoryConfig.Complete(s.Etcd, s.StorageSerialization)
|
||||
completedStorageFactoryConfig, err := storageFactoryConfig.Complete(s.Etcd)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
return
|
||||
|
|
|
@ -19,8 +19,6 @@ package kubeapiserver
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
serveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
|
@ -37,7 +35,6 @@ import (
|
|||
"k8s.io/kubernetes/pkg/apis/networking"
|
||||
"k8s.io/kubernetes/pkg/apis/policy"
|
||||
apisstorage "k8s.io/kubernetes/pkg/apis/storage"
|
||||
kubeapiserveroptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
|
||||
)
|
||||
|
||||
// SpecialDefaultResourcePrefixes are prefixes compiled into Kubernetes.
|
||||
|
@ -68,18 +65,12 @@ type StorageFactoryConfig struct {
|
|||
DefaultResourceEncoding *serverstorage.DefaultResourceEncodingConfig
|
||||
DefaultStorageMediaType string
|
||||
Serializer runtime.StorageSerializer
|
||||
StorageEncodingOverrides map[string]schema.GroupVersion
|
||||
ResourceEncodingOverrides []schema.GroupVersionResource
|
||||
EtcdServersOverrides []string
|
||||
EncryptionProviderConfigFilepath string
|
||||
}
|
||||
|
||||
func (c *StorageFactoryConfig) Complete(etcdOptions *serveroptions.EtcdOptions, serializationOptions *kubeapiserveroptions.StorageSerializationOptions) (*completedStorageFactoryConfig, error) {
|
||||
storageGroupsToEncodingVersion, err := serializationOptions.StorageGroupsToEncodingVersion()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating storage version map: %s", err)
|
||||
}
|
||||
c.StorageEncodingOverrides = storageGroupsToEncodingVersion
|
||||
func (c *StorageFactoryConfig) Complete(etcdOptions *serveroptions.EtcdOptions) (*completedStorageFactoryConfig, error) {
|
||||
c.StorageConfig = etcdOptions.StorageConfig
|
||||
c.DefaultStorageMediaType = etcdOptions.DefaultStorageMediaType
|
||||
c.EtcdServersOverrides = etcdOptions.EtcdServersOverrides
|
||||
|
@ -92,8 +83,7 @@ type completedStorageFactoryConfig struct {
|
|||
}
|
||||
|
||||
func (c *completedStorageFactoryConfig) New() (*serverstorage.DefaultStorageFactory, error) {
|
||||
resourceEncodingConfig := resourceconfig.MergeGroupEncodingConfigs(c.DefaultResourceEncoding, c.StorageEncodingOverrides)
|
||||
resourceEncodingConfig = resourceconfig.MergeResourceEncodingConfigs(resourceEncodingConfig, c.ResourceEncodingOverrides)
|
||||
resourceEncodingConfig := resourceconfig.MergeResourceEncodingConfigs(c.DefaultResourceEncoding, c.ResourceEncodingOverrides)
|
||||
storageFactory := serverstorage.NewDefaultStorageFactory(
|
||||
c.StorageConfig,
|
||||
c.DefaultStorageMediaType,
|
||||
|
|
|
@ -27,3 +27,5 @@ var DefaultServiceNodePortRange = utilnet.PortRange{Base: 30000, Size: 2768}
|
|||
|
||||
// DefaultServiceIPCIDR is a CIDR notation of IP range from which to allocate service cluster IPs
|
||||
var DefaultServiceIPCIDR net.IPNet = net.IPNet{IP: net.ParseIP("10.0.0.0"), Mask: net.CIDRMask(24, 32)}
|
||||
|
||||
const DefaultEtcdPathPrefix = "/registry"
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultEtcdPathPrefix = "/registry"
|
||||
)
|
||||
|
||||
// StorageSerializationOptions contains the options for encoding resources.
|
||||
type StorageSerializationOptions struct {
|
||||
StorageVersions string
|
||||
// The default values for StorageVersions. StorageVersions overrides
|
||||
// these; you can change this if you want to change the defaults (e.g.,
|
||||
// for testing). This is not actually exposed as a flag.
|
||||
DefaultStorageVersions string
|
||||
}
|
||||
|
||||
func NewStorageSerializationOptions() *StorageSerializationOptions {
|
||||
return &StorageSerializationOptions{
|
||||
DefaultStorageVersions: ToPreferredVersionString(legacyscheme.Scheme.PreferredVersionAllGroups()),
|
||||
StorageVersions: ToPreferredVersionString(legacyscheme.Scheme.PreferredVersionAllGroups()),
|
||||
}
|
||||
}
|
||||
|
||||
// StorageGroupsToEncodingVersion returns a map from group name to group version,
|
||||
// computed from s.StorageVersions flag.
|
||||
func (s *StorageSerializationOptions) StorageGroupsToEncodingVersion() (map[string]schema.GroupVersion, error) {
|
||||
storageVersionMap := map[string]schema.GroupVersion{}
|
||||
|
||||
// First, get the defaults.
|
||||
if err := mergeGroupVersionIntoMap(s.DefaultStorageVersions, storageVersionMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Override any defaults with the user settings.
|
||||
if err := mergeGroupVersionIntoMap(s.StorageVersions, storageVersionMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return storageVersionMap, nil
|
||||
}
|
||||
|
||||
// dest must be a map of group to groupVersion.
|
||||
func mergeGroupVersionIntoMap(gvList string, dest map[string]schema.GroupVersion) error {
|
||||
for _, gvString := range strings.Split(gvList, ",") {
|
||||
if gvString == "" {
|
||||
continue
|
||||
}
|
||||
// We accept two formats. "group/version" OR
|
||||
// "group=group/version". The latter is used when types
|
||||
// move between groups.
|
||||
if !strings.Contains(gvString, "=") {
|
||||
gv, err := schema.ParseGroupVersion(gvString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dest[gv.Group] = gv
|
||||
|
||||
} else {
|
||||
parts := strings.SplitN(gvString, "=", 2)
|
||||
gv, err := schema.ParseGroupVersion(parts[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dest[parts[0]] = gv
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddFlags adds flags for a specific APIServer to the specified FlagSet
|
||||
func (s *StorageSerializationOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
||||
// arrange these text blocks sensibly. Grrr.
|
||||
fs.StringVar(&s.StorageVersions, "storage-versions", s.StorageVersions, ""+
|
||||
"The per-group version to store resources in. "+
|
||||
"Specified in the format \"group1/version1,group2/version2,...\". "+
|
||||
"In the case where objects are moved from one group to the other, "+
|
||||
"you may specify the format \"group1=group2/v1beta1,group3/v1beta1,...\". "+
|
||||
"You only need to pass the groups you wish to change from the defaults. "+
|
||||
"It defaults to a list of preferred versions of all known groups.")
|
||||
|
||||
fs.MarkDeprecated("storage-versions", ""+
|
||||
"Please omit this flag to ensure the default storage versions are used ."+
|
||||
"Otherwise the cluster is not safe to upgrade to a version newer than 1.12. "+
|
||||
"This flag will be removed in 1.13.")
|
||||
|
||||
}
|
||||
|
||||
// ToPreferredVersionString returns the preferred versions of all registered
|
||||
// groups in the form of "group1/version1,group2/version2,...". This is compatible
|
||||
// with the flag format
|
||||
func ToPreferredVersionString(versions []schema.GroupVersion) string {
|
||||
var defaults []string
|
||||
for _, version := range versions {
|
||||
defaults = append(defaults, version.String())
|
||||
}
|
||||
// sorting provides stable output for help.
|
||||
sort.Strings(defaults)
|
||||
return strings.Join(defaults, ",")
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func TestGenerateStorageVersionMap(t *testing.T) {
|
||||
testCases := []struct {
|
||||
storageVersions string
|
||||
defaultVersions string
|
||||
expectedMap map[string]schema.GroupVersion
|
||||
}{
|
||||
{
|
||||
storageVersions: "v1,extensions/v1beta1",
|
||||
expectedMap: map[string]schema.GroupVersion{
|
||||
"": {Version: "v1"},
|
||||
"extensions": {Group: "extensions", Version: "v1beta1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
storageVersions: "extensions/v1beta1,v1",
|
||||
expectedMap: map[string]schema.GroupVersion{
|
||||
"": {Version: "v1"},
|
||||
"extensions": {Group: "extensions", Version: "v1beta1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
storageVersions: "autoscaling=extensions/v1beta1,v1",
|
||||
defaultVersions: "extensions/v1beta1,v1,autoscaling/v1",
|
||||
expectedMap: map[string]schema.GroupVersion{
|
||||
"": {Version: "v1"},
|
||||
"autoscaling": {Group: "extensions", Version: "v1beta1"},
|
||||
"extensions": {Group: "extensions", Version: "v1beta1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
storageVersions: "",
|
||||
expectedMap: map[string]schema.GroupVersion{},
|
||||
},
|
||||
}
|
||||
for i, test := range testCases {
|
||||
s := &StorageSerializationOptions{
|
||||
StorageVersions: test.storageVersions,
|
||||
DefaultStorageVersions: test.defaultVersions,
|
||||
}
|
||||
output, err := s.StorageGroupsToEncodingVersion()
|
||||
if err != nil {
|
||||
t.Errorf("%v: unexpected error: %v", i, err)
|
||||
}
|
||||
if !reflect.DeepEqual(test.expectedMap, output) {
|
||||
t.Errorf("%v: unexpected error. expect: %v, got: %v", i, test.expectedMap, output)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue