Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 85d1d29

Browse files
author
Dongsu Park
committed
fleetctl: take experimentalAPI into account in getClient
getClient() has not taken into account the case of !experimentalAPI, before calling registryClient. It has set endPoint to a specific value of URLs, but the new value would not be passed to getRegistryClient(), which simply fetches endPoint again. This was a regression since 848d356 ("fleetctl: convert cli to cobra"). To fix that, introduce getEndpoint() that does GetString("endpoint") as well as the special handling for experimentalAPI. And make getRegistryClient() call getEndpoint(). Fortunately, the experimentalAPI flag is set to true by default, so this special handling path is not actively used after all. Just for correctness.
1 parent 2b2eda2 commit 85d1d29

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

fleetctl/fleetctl.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,7 @@ func getClientAPI(cCmd *cobra.Command) client.API {
319319

320320
// getClient initializes a client of fleet based on CLI flags
321321
func getClient(cCmd *cobra.Command) (client.API, error) {
322-
// The user explicitly set --experimental-api=false, so it trumps the
323-
// --driver flag. This behavior exists for backwards-compatibilty.
324-
experimentalAPI, _ := cmdFleet.PersistentFlags().GetBool("experimental-api")
325-
endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
326322
clientDriver, _ := cmdFleet.PersistentFlags().GetString("driver")
327-
if !experimentalAPI {
328-
// Additionally, if the user set --experimental-api=false and did
329-
// not change the value of --endpoint, they likely want to use the
330-
// old default value.
331-
if endPoint == defaultEndpoint {
332-
endPoint = "http://127.0.0.1:2379,http://127.0.0.1:4001"
333-
}
334-
return getRegistryClient(cCmd)
335-
}
336323

337324
switch clientDriver {
338325
case clientDriverAPI:
@@ -437,6 +424,22 @@ func getHTTPClient(cCmd *cobra.Command) (client.API, error) {
437424
return client.NewHTTPClient(&hc, *ep)
438425
}
439426

427+
func getEndpoint() string {
428+
// The user explicitly set --experimental-api=false, so it trumps the
429+
// --driver flag. This behavior exists for backwards-compatibilty.
430+
experimentalAPI, _ := cmdFleet.PersistentFlags().GetBool("experimental-api")
431+
endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
432+
if !experimentalAPI {
433+
// Additionally, if the user set --experimental-api=false and did
434+
// not change the value of --endpoint, they likely want to use the
435+
// old default value.
436+
if endPoint == defaultEndpoint {
437+
endPoint = "http://127.0.0.1:2379,http://127.0.0.1:4001"
438+
}
439+
}
440+
return endPoint
441+
}
442+
440443
func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
441444
var dial func(string, string) (net.Conn, error)
442445
SSHUserName, _ := cmdFleet.PersistentFlags().GetString("ssh-username")
@@ -469,9 +472,8 @@ func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
469472
TLSClientConfig: tlsConfig,
470473
}
471474

472-
endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
473475
eCfg := etcd.Config{
474-
Endpoints: strings.Split(endPoint, ","),
476+
Endpoints: strings.Split(getEndpoint(), ","),
475477
Transport: trans,
476478
HeaderTimeoutPerRequest: getRequestTimeoutFlag(cCmd),
477479
}

0 commit comments

Comments
 (0)