etcd2 code cleanup, remove deserialization cache

Kubernetes-commit: c8db31b84adc40aa875917fbca27b2a787902088
This commit is contained in:
Jordan Liggitt 2018-10-15 22:17:44 -04:00 committed by Kubernetes Publisher
parent 0221fe2249
commit c7c9a358c2
5 changed files with 47 additions and 62 deletions

View File

@ -59,7 +59,6 @@ type EtcdOptions struct {
}
var storageTypes = sets.NewString(
storagebackend.StorageTypeUnset,
storagebackend.StorageTypeETCD3,
)
@ -86,8 +85,8 @@ func (s *EtcdOptions) Validate() []error {
allErrors = append(allErrors, fmt.Errorf("--etcd-servers must be specified"))
}
if !storageTypes.Has(s.StorageConfig.Type) {
allErrors = append(allErrors, fmt.Errorf("--storage-backend invalid, must be 'etcd3' or 'etcd2'. If not specified, it will default to 'etcd3'"))
if s.StorageConfig.Type != storagebackend.StorageTypeUnset && !storageTypes.Has(s.StorageConfig.Type) {
allErrors = append(allErrors, fmt.Errorf("--storage-backend invalid, allowed values: %s. If not specified, it will default to 'etcd3'", strings.Join(storageTypes.List(), ", ")))
}
for _, override := range s.EtcdServersOverrides {
@ -142,10 +141,11 @@ func (s *EtcdOptions) AddFlags(fs *pflag.FlagSet) {
"have system defaults set by heuristics, others default to default-watch-cache-size")
fs.StringVar(&s.StorageConfig.Type, "storage-backend", s.StorageConfig.Type,
"The storage backend for persistence. Options: 'etcd3' (default), 'etcd2'.")
"The storage backend for persistence. Options: 'etcd3' (default).")
fs.IntVar(&s.StorageConfig.DeserializationCacheSize, "deserialization-cache-size", s.StorageConfig.DeserializationCacheSize,
"Number of deserialized json objects to cache in memory.")
dummyCacheSize := 0
fs.IntVar(&dummyCacheSize, "deserialization-cache-size", 0, "Number of deserialized json objects to cache in memory.")
fs.MarkDeprecated("deserialization-cache-size", "the deserialization cache was dropped in 1.13 with support for etcd2")
fs.StringSliceVar(&s.StorageConfig.ServerList, "etcd-servers", s.StorageConfig.ServerList,
"List of etcd servers to connect with (scheme://ip:port), comma separated.")

View File

@ -36,15 +36,14 @@ func TestEtcdOptionsValidate(t *testing.T) {
name: "test when ServerList is not specified",
testOptions: &EtcdOptions{
StorageConfig: storagebackend.Config{
Type: "etcd2",
ServerList: nil,
Prefix: "/registry",
DeserializationCacheSize: 0,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
Type: "etcd3",
ServerList: nil,
Prefix: "/registry",
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
},
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
DeleteCollectionWorkers: 1,
@ -59,15 +58,14 @@ func TestEtcdOptionsValidate(t *testing.T) {
name: "test when storage-backend is invalid",
testOptions: &EtcdOptions{
StorageConfig: storagebackend.Config{
Type: "etcd4",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
DeserializationCacheSize: 0,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
Type: "etcd4",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
},
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
DeleteCollectionWorkers: 1,
@ -76,21 +74,20 @@ func TestEtcdOptionsValidate(t *testing.T) {
DefaultWatchCacheSize: 100,
EtcdServersOverrides: []string{"/events#http://127.0.0.1:4002"},
},
expectErr: "--storage-backend invalid, must be 'etcd3' or 'etcd2'. If not specified, it will default to 'etcd3'",
expectErr: "--storage-backend invalid, allowed values: etcd3. If not specified, it will default to 'etcd3'",
},
{
name: "test when etcd-servers-overrides is invalid",
testOptions: &EtcdOptions{
StorageConfig: storagebackend.Config{
Type: "etcd3",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
DeserializationCacheSize: 0,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
Type: "etcd3",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
},
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
DeleteCollectionWorkers: 1,
@ -105,15 +102,14 @@ func TestEtcdOptionsValidate(t *testing.T) {
name: "test when EtcdOptions is valid",
testOptions: &EtcdOptions{
StorageConfig: storagebackend.Config{
Type: "etcd3",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
DeserializationCacheSize: 0,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
Type: "etcd3",
ServerList: []string{"http://127.0.0.1"},
Prefix: "/registry",
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
CountMetricPollPeriod: time.Minute,
},
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
DeleteCollectionWorkers: 1,

View File

@ -21,9 +21,6 @@ import (
"path"
)
// Cache size to use for tests.
const DeserializationCacheSize = 150
// Returns the prefix set via the ETCD_PREFIX environment variable (if any).
func PathPrefix() string {
pref := os.Getenv("ETCD_PREFIX")

View File

@ -293,11 +293,10 @@ func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storageb
}
server.V3Client = server.v3Cluster.RandClient()
config := &storagebackend.Config{
Type: "etcd3",
Prefix: etcdtest.PathPrefix(),
ServerList: server.V3Client.Endpoints(),
DeserializationCacheSize: etcdtest.DeserializationCacheSize,
Paging: true,
Type: "etcd3",
Prefix: etcdtest.PathPrefix(),
ServerList: server.V3Client.Endpoints(),
Paging: true,
}
return server, config
}

View File

@ -32,7 +32,7 @@ const (
// Config is configuration for creating a storage backend.
type Config struct {
// Type defines the type of storage backend, e.g. "etcd2", etcd3". Default ("") is "etcd3".
// Type defines the type of storage backend. Default ("") is "etcd3".
Type string
// Prefix is the prefix to all keys passed to storage.Interface methods.
Prefix string
@ -47,10 +47,6 @@ type Config struct {
// resource type not wishing to allow paging, and is not intended for end users to
// set.
Paging bool
// DeserializationCacheSize is the size of cache of deserialized objects.
// Currently this is only supported in etcd2.
// We will drop the cache once using protobuf.
DeserializationCacheSize int
Codec runtime.Codec
// Transformer allows the value to be transformed prior to persisting into etcd.
@ -66,11 +62,8 @@ type Config struct {
func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
return &Config{
Prefix: prefix,
// Default cache size to 0 - if unset, its size will be set based on target
// memory usage.
DeserializationCacheSize: 0,
Codec: codec,
CompactionInterval: DefaultCompactInterval,
Prefix: prefix,
Codec: codec,
CompactionInterval: DefaultCompactInterval,
}
}