mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
etcd2 code cleanup, remove deserialization cache
This commit is contained in:
parent
b11211ed8c
commit
c8db31b84a
@ -111,7 +111,7 @@ func TestAddFlags(t *testing.T) {
|
|||||||
"--proxy-client-cert-file=/var/run/kubernetes/proxy.crt",
|
"--proxy-client-cert-file=/var/run/kubernetes/proxy.crt",
|
||||||
"--proxy-client-key-file=/var/run/kubernetes/proxy.key",
|
"--proxy-client-key-file=/var/run/kubernetes/proxy.key",
|
||||||
"--request-timeout=2m",
|
"--request-timeout=2m",
|
||||||
"--storage-backend=etcd2",
|
"--storage-backend=etcd3",
|
||||||
}
|
}
|
||||||
fs.Parse(args)
|
fs.Parse(args)
|
||||||
|
|
||||||
@ -141,10 +141,9 @@ func TestAddFlags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Etcd: &apiserveroptions.EtcdOptions{
|
Etcd: &apiserveroptions.EtcdOptions{
|
||||||
StorageConfig: storagebackend.Config{
|
StorageConfig: storagebackend.Config{
|
||||||
Type: "etcd2",
|
Type: "etcd3",
|
||||||
ServerList: nil,
|
ServerList: nil,
|
||||||
Prefix: "/registry",
|
Prefix: "/registry",
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
KeyFile: "/var/run/kubernetes/etcd.key",
|
KeyFile: "/var/run/kubernetes/etcd.key",
|
||||||
CAFile: "/var/run/kubernetes/etcdca.crt",
|
CAFile: "/var/run/kubernetes/etcdca.crt",
|
||||||
CertFile: "/var/run/kubernetes/etcdce.crt",
|
CertFile: "/var/run/kubernetes/etcdce.crt",
|
||||||
|
@ -699,27 +699,6 @@ func Complete(s *options.ServerRunOptions) (completedServerRunOptions, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Etcd.StorageConfig.DeserializationCacheSize == 0 {
|
|
||||||
// When size of cache is not explicitly set, estimate its size based on
|
|
||||||
// target memory usage.
|
|
||||||
glog.V(2).Infof("Initializing deserialization cache size based on %dMB limit", s.GenericServerRunOptions.TargetRAMMB)
|
|
||||||
|
|
||||||
// This is the heuristics that from memory capacity is trying to infer
|
|
||||||
// the maximum number of nodes in the cluster and set cache sizes based
|
|
||||||
// on that value.
|
|
||||||
// From our documentation, we officially recommend 120GB machines for
|
|
||||||
// 2000 nodes, and we scale from that point. Thus we assume ~60MB of
|
|
||||||
// capacity per node.
|
|
||||||
// TODO: We may consider deciding that some percentage of memory will
|
|
||||||
// be used for the deserialization cache and divide it by the max object
|
|
||||||
// size to compute its size. We may even go further and measure
|
|
||||||
// collective sizes of the objects in the cache.
|
|
||||||
clusterSize := s.GenericServerRunOptions.TargetRAMMB / 60
|
|
||||||
s.Etcd.StorageConfig.DeserializationCacheSize = 25 * clusterSize
|
|
||||||
if s.Etcd.StorageConfig.DeserializationCacheSize < 1000 {
|
|
||||||
s.Etcd.StorageConfig.DeserializationCacheSize = 1000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if s.Etcd.EnableWatchCache {
|
if s.Etcd.EnableWatchCache {
|
||||||
glog.V(2).Infof("Initializing cache sizes based on %dMB limit", s.GenericServerRunOptions.TargetRAMMB)
|
glog.V(2).Infof("Initializing cache sizes based on %dMB limit", s.GenericServerRunOptions.TargetRAMMB)
|
||||||
sizes := cachesize.NewHeuristicWatchCacheSizes(s.GenericServerRunOptions.TargetRAMMB)
|
sizes := cachesize.NewHeuristicWatchCacheSizes(s.GenericServerRunOptions.TargetRAMMB)
|
||||||
|
@ -59,7 +59,6 @@ type EtcdOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var storageTypes = sets.NewString(
|
var storageTypes = sets.NewString(
|
||||||
storagebackend.StorageTypeUnset,
|
|
||||||
storagebackend.StorageTypeETCD3,
|
storagebackend.StorageTypeETCD3,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -86,8 +85,8 @@ func (s *EtcdOptions) Validate() []error {
|
|||||||
allErrors = append(allErrors, fmt.Errorf("--etcd-servers must be specified"))
|
allErrors = append(allErrors, fmt.Errorf("--etcd-servers must be specified"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !storageTypes.Has(s.StorageConfig.Type) {
|
if s.StorageConfig.Type != storagebackend.StorageTypeUnset && !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'"))
|
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 {
|
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")
|
"have system defaults set by heuristics, others default to default-watch-cache-size")
|
||||||
|
|
||||||
fs.StringVar(&s.StorageConfig.Type, "storage-backend", s.StorageConfig.Type,
|
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,
|
dummyCacheSize := 0
|
||||||
"Number of deserialized json objects to cache in memory.")
|
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,
|
fs.StringSliceVar(&s.StorageConfig.ServerList, "etcd-servers", s.StorageConfig.ServerList,
|
||||||
"List of etcd servers to connect with (scheme://ip:port), comma separated.")
|
"List of etcd servers to connect with (scheme://ip:port), comma separated.")
|
||||||
|
@ -36,10 +36,9 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
name: "test when ServerList is not specified",
|
name: "test when ServerList is not specified",
|
||||||
testOptions: &EtcdOptions{
|
testOptions: &EtcdOptions{
|
||||||
StorageConfig: storagebackend.Config{
|
StorageConfig: storagebackend.Config{
|
||||||
Type: "etcd2",
|
Type: "etcd3",
|
||||||
ServerList: nil,
|
ServerList: nil,
|
||||||
Prefix: "/registry",
|
Prefix: "/registry",
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
KeyFile: "/var/run/kubernetes/etcd.key",
|
KeyFile: "/var/run/kubernetes/etcd.key",
|
||||||
CAFile: "/var/run/kubernetes/etcdca.crt",
|
CAFile: "/var/run/kubernetes/etcdca.crt",
|
||||||
CertFile: "/var/run/kubernetes/etcdce.crt",
|
CertFile: "/var/run/kubernetes/etcdce.crt",
|
||||||
@ -62,7 +61,6 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
Type: "etcd4",
|
Type: "etcd4",
|
||||||
ServerList: []string{"http://127.0.0.1"},
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
Prefix: "/registry",
|
Prefix: "/registry",
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
KeyFile: "/var/run/kubernetes/etcd.key",
|
KeyFile: "/var/run/kubernetes/etcd.key",
|
||||||
CAFile: "/var/run/kubernetes/etcdca.crt",
|
CAFile: "/var/run/kubernetes/etcdca.crt",
|
||||||
CertFile: "/var/run/kubernetes/etcdce.crt",
|
CertFile: "/var/run/kubernetes/etcdce.crt",
|
||||||
@ -76,7 +74,7 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
DefaultWatchCacheSize: 100,
|
DefaultWatchCacheSize: 100,
|
||||||
EtcdServersOverrides: []string{"/events#http://127.0.0.1:4002"},
|
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",
|
name: "test when etcd-servers-overrides is invalid",
|
||||||
@ -85,7 +83,6 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
Type: "etcd3",
|
Type: "etcd3",
|
||||||
ServerList: []string{"http://127.0.0.1"},
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
Prefix: "/registry",
|
Prefix: "/registry",
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
KeyFile: "/var/run/kubernetes/etcd.key",
|
KeyFile: "/var/run/kubernetes/etcd.key",
|
||||||
CAFile: "/var/run/kubernetes/etcdca.crt",
|
CAFile: "/var/run/kubernetes/etcdca.crt",
|
||||||
CertFile: "/var/run/kubernetes/etcdce.crt",
|
CertFile: "/var/run/kubernetes/etcdce.crt",
|
||||||
@ -108,7 +105,6 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
Type: "etcd3",
|
Type: "etcd3",
|
||||||
ServerList: []string{"http://127.0.0.1"},
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
Prefix: "/registry",
|
Prefix: "/registry",
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
KeyFile: "/var/run/kubernetes/etcd.key",
|
KeyFile: "/var/run/kubernetes/etcd.key",
|
||||||
CAFile: "/var/run/kubernetes/etcdca.crt",
|
CAFile: "/var/run/kubernetes/etcdca.crt",
|
||||||
CertFile: "/var/run/kubernetes/etcdce.crt",
|
CertFile: "/var/run/kubernetes/etcdce.crt",
|
||||||
|
@ -21,9 +21,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache size to use for tests.
|
|
||||||
const DeserializationCacheSize = 150
|
|
||||||
|
|
||||||
// Returns the prefix set via the ETCD_PREFIX environment variable (if any).
|
// Returns the prefix set via the ETCD_PREFIX environment variable (if any).
|
||||||
func PathPrefix() string {
|
func PathPrefix() string {
|
||||||
pref := os.Getenv("ETCD_PREFIX")
|
pref := os.Getenv("ETCD_PREFIX")
|
||||||
|
@ -296,7 +296,6 @@ func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storageb
|
|||||||
Type: "etcd3",
|
Type: "etcd3",
|
||||||
Prefix: etcdtest.PathPrefix(),
|
Prefix: etcdtest.PathPrefix(),
|
||||||
ServerList: server.V3Client.Endpoints(),
|
ServerList: server.V3Client.Endpoints(),
|
||||||
DeserializationCacheSize: etcdtest.DeserializationCacheSize,
|
|
||||||
Paging: true,
|
Paging: true,
|
||||||
}
|
}
|
||||||
return server, config
|
return server, config
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
|
|
||||||
// Config is configuration for creating a storage backend.
|
// Config is configuration for creating a storage backend.
|
||||||
type Config struct {
|
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
|
Type string
|
||||||
// Prefix is the prefix to all keys passed to storage.Interface methods.
|
// Prefix is the prefix to all keys passed to storage.Interface methods.
|
||||||
Prefix string
|
Prefix string
|
||||||
@ -47,10 +47,6 @@ type Config struct {
|
|||||||
// resource type not wishing to allow paging, and is not intended for end users to
|
// resource type not wishing to allow paging, and is not intended for end users to
|
||||||
// set.
|
// set.
|
||||||
Paging bool
|
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
|
Codec runtime.Codec
|
||||||
// Transformer allows the value to be transformed prior to persisting into etcd.
|
// Transformer allows the value to be transformed prior to persisting into etcd.
|
||||||
@ -67,9 +63,6 @@ type Config struct {
|
|||||||
func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
|
func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
// Default cache size to 0 - if unset, its size will be set based on target
|
|
||||||
// memory usage.
|
|
||||||
DeserializationCacheSize: 0,
|
|
||||||
Codec: codec,
|
Codec: codec,
|
||||||
CompactionInterval: DefaultCompactInterval,
|
CompactionInterval: DefaultCompactInterval,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user