Skip to content

Commit

Permalink
Rename ClientConfig to ConfigSpec
Browse files Browse the repository at this point in the history
The ClientConfig is a fully declarive configuration, so it makes more
sense to rename it to ConfigSpec. It can also mitigate the confusion
between Config and ClientConfig.
  • Loading branch information
ahrtr committed Mar 12, 2022
1 parent 3dcbbf6 commit 1a3822f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
5 changes: 4 additions & 1 deletion client/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 3 additions & 3 deletions etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/make_mirror_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions server/etcdserver/api/v3discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -77,18 +77,18 @@ type clusterInfo struct {
}

// key prefix for each cluster: "/_etcd/registry/<ClusterToken>".
func geClusterKeyPrefix(cluster string) string {
func getClusterKeyPrefix(cluster string) string {
return path.Join(discoveryPrefix, cluster)
}

// key format for cluster size: "/_etcd/registry/<ClusterToken>/_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/<ClusterToken>/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/<ClusterToken>/members/<memberId>".
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 1a3822f

Please sign in to comment.