diff --git a/client/v3/config.go b/client/v3/config.go index eaa409f0ff05..29726160852a 100644 --- a/client/v3/config.go +++ b/client/v3/config.go @@ -91,7 +91,10 @@ type Config struct { // TODO: support custom balancer picker } -type ClientConfig struct { +// ConfigSpec is the configuration from users, which comes from command-line flags, +// environment variables or config file. It is a fully declarative configuration, +// and can be serialized & deserialized to/from JSON. +type ConfigSpec struct { Endpoints []string `json:"endpoints"` RequestTimeout time.Duration `json:"request-timeout"` DialTimeout time.Duration `json:"dial-timeout"` diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index e67ea84c91b3..57adae28f00a 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -88,7 +88,7 @@ func (*discardValue) String() string { return "" } func (*discardValue) Set(string) error { return nil } func (*discardValue) Type() string { return "" } -func clientConfigFromCmd(cmd *cobra.Command) *clientv3.ClientConfig { +func clientConfigFromCmd(cmd *cobra.Command) *clientv3.ConfigSpec { lg, err := zap.NewProduction() if err != nil { cobrautl.ExitWithError(cobrautl.ExitError, err) @@ -119,7 +119,7 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientv3.ClientConfig { grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, os.Stderr)) } - cfg := &clientv3.ClientConfig{} + cfg := &clientv3.ConfigSpec{} cfg.Endpoints, err = endpointsFromCmd(cmd) if err != nil { cobrautl.ExitWithError(cobrautl.ExitError, err) @@ -150,7 +150,7 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { return mustClient(cfg) } -func mustClient(cc *clientv3.ClientConfig) *clientv3.Client { +func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client { cfg, err := newClientCfg(cc.Endpoints, cc.DialTimeout, cc.KeepAliveTime, cc.KeepAliveTimeout, cc.Secure, cc.Auth) if err != nil { cobrautl.ExitWithError(cobrautl.ExitBadArgs, err) diff --git a/etcdctl/ctlv3/command/make_mirror_command.go b/etcdctl/ctlv3/command/make_mirror_command.go index 0604373b3e77..e93e108ea1d3 100644 --- a/etcdctl/ctlv3/command/make_mirror_command.go +++ b/etcdctl/ctlv3/command/make_mirror_command.go @@ -114,7 +114,7 @@ func makeMirrorCommandFunc(cmd *cobra.Command, args []string) { auth := authDestCfg() - cc := &clientv3.ClientConfig{ + cc := &clientv3.ConfigSpec{ Endpoints: []string{args[0]}, DialTimeout: dialTimeout, KeepAliveTime: keepAliveTime, diff --git a/server/embed/config.go b/server/embed/config.go index 2c86a29f9421..21218e66e1c0 100644 --- a/server/embed/config.go +++ b/server/embed/config.go @@ -517,7 +517,7 @@ func NewConfig() *Config { V2Deprecation: config.V2_DEPR_DEFAULT, DiscoveryCfg: v3discovery.DiscoveryConfig{ - ClientConfig: clientv3.ClientConfig{ + ConfigSpec: clientv3.ConfigSpec{ DialTimeout: DefaultDiscoveryDialTimeout, RequestTimeout: DefaultDiscoveryRequestTimeOut, KeepAliveTime: DefaultDiscoveryKeepAliveTime, diff --git a/server/etcdserver/api/v3discovery/discovery.go b/server/etcdserver/api/v3discovery/discovery.go index 1a6e1d22638f..1c274cdba17f 100644 --- a/server/etcdserver/api/v3discovery/discovery.go +++ b/server/etcdserver/api/v3discovery/discovery.go @@ -55,8 +55,8 @@ var ( ) type DiscoveryConfig struct { - clientv3.ClientConfig `json:"client"` - Token string `json:"token"` + clientv3.ConfigSpec `json:"client"` + Token string `json:"token"` } type memberInfo struct { @@ -77,18 +77,18 @@ type clusterInfo struct { } // key prefix for each cluster: "/_etcd/registry/". -func geClusterKeyPrefix(cluster string) string { +func getClusterKeyPrefix(cluster string) string { return path.Join(discoveryPrefix, cluster) } // key format for cluster size: "/_etcd/registry//_config/size". -func geClusterSizeKey(cluster string) string { - return path.Join(geClusterKeyPrefix(cluster), "_config/size") +func getClusterSizeKey(cluster string) string { + return path.Join(getClusterKeyPrefix(cluster), "_config/size") } // key prefix for each member: "/_etcd/registry//members". func getMemberKeyPrefix(clusterToken string) string { - return path.Join(geClusterKeyPrefix(clusterToken), "members") + return path.Join(getClusterKeyPrefix(clusterToken), "members") } // key format for each member: "/_etcd/registry//members/". @@ -278,7 +278,7 @@ func (d *discovery) joinCluster(config string) (string, error) { } func (d *discovery) getClusterSize() (int, error) { - configKey := geClusterSizeKey(d.clusterToken) + configKey := getClusterSizeKey(d.clusterToken) ctx, cancel := context.WithTimeout(context.Background(), d.cfg.RequestTimeout) defer cancel()