Skip to content

Commit

Permalink
update epHealthCommandFunc to reuse clientConfigFromCmd
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
  • Loading branch information
ahrtr committed Oct 14, 2024
1 parent 04efee2 commit 34b8fa1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
20 changes: 20 additions & 0 deletions client/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ type AuthConfig struct {
Password string `json:"password"`
}

func (cs *ConfigSpec) Clone() *ConfigSpec {
if cs == nil {
return nil
}

clone := *cs

if len(cs.Endpoints) > 0 {
clone.Endpoints = make([]string, len(cs.Endpoints))
copy(clone.Endpoints, cs.Endpoints)
}

clone.Secure = &SecureConfig{}
*clone.Secure = *cs.Secure
clone.Auth = &AuthConfig{}
*clone.Auth = *cs.Auth

return &clone
}

func (cfg AuthConfig) Empty() bool {
return cfg.Username == "" && cfg.Password == ""
}
Expand Down
18 changes: 5 additions & 13 deletions etcdctl/ctlv3/command/ep_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,13 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
flags.SetPflagsFromEnv(lg, "ETCDCTL", cmd.InheritedFlags())
initDisplayFromCmd(cmd)

sec := secureCfgFromCmd(cmd)
dt := dialTimeoutFromCmd(cmd)
ka := keepAliveTimeFromCmd(cmd)
kat := keepAliveTimeoutFromCmd(cmd)
auth := authCfgFromCmd(cmd)
cfgSpec := clientConfigFromCmd(cmd)

var cfgs []*clientv3.Config
for _, ep := range endpointsFromCluster(cmd) {
cfg, err := clientv3.NewClientConfig(&clientv3.ConfigSpec{
Endpoints: []string{ep},
DialTimeout: dt,
KeepAliveTime: ka,
KeepAliveTimeout: kat,
Secure: sec,
Auth: auth,
}, lg)
cloneCfgSpec := cfgSpec.Clone()
cloneCfgSpec.Endpoints = []string{ep}
cfg, err := clientv3.NewClientConfig(cloneCfgSpec, lg)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}
Expand Down

0 comments on commit 34b8fa1

Please sign in to comment.