forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
etcd.go
48 lines (41 loc) · 1.72 KB
/
etcd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package configprocessing
import (
configv1 "github.com/openshift/api/config/v1"
cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
"k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/storage/storagebackend"
)
// GetEtcdOptions takes configuration information and flag overrides to produce the upstream etcdoptions.
func GetEtcdOptions(startingFlags map[string][]string, serializedConfig configv1.EtcdStorageConfig, defaultWatchCacheSizes map[schema.GroupResource]int) (*options.EtcdOptions, error) {
storageConfig := storagebackend.NewDefaultConfig(serializedConfig.StoragePrefix, nil)
storageConfig.Type = "etcd3"
storageConfig.ServerList = serializedConfig.URLs
storageConfig.KeyFile = serializedConfig.KeyFile
storageConfig.CertFile = serializedConfig.CertFile
storageConfig.CAFile = serializedConfig.CA
etcdOptions := options.NewEtcdOptions(storageConfig)
etcdOptions.DefaultStorageMediaType = "application/vnd.kubernetes.protobuf"
etcdOptions.DefaultWatchCacheSize = 0
if err := cmdflags.ResolveIgnoreMissing(startingFlags, etcdOptions.AddFlags); len(err) > 0 {
return nil, utilerrors.NewAggregate(err)
}
if etcdOptions.EnableWatchCache {
watchCacheSizes := map[schema.GroupResource]int{}
for k, v := range defaultWatchCacheSizes {
watchCacheSizes[k] = v
}
if userSpecified, err := options.ParseWatchCacheSizes(etcdOptions.WatchCacheSizes); err == nil {
for resource, size := range userSpecified {
watchCacheSizes[resource] = size
}
}
var err error
etcdOptions.WatchCacheSizes, err = options.WriteWatchCacheSizes(watchCacheSizes)
if err != nil {
return nil, err
}
}
return etcdOptions, nil
}