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

Commit

Permalink
fleetctl: take experimentalAPI into account in getClient
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dongsu Park committed Nov 9, 2016
1 parent 2b2eda2 commit 85d1d29
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,7 @@ func getClientAPI(cCmd *cobra.Command) client.API {

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

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

func getEndpoint() string {
// The user explicitly set --experimental-api=false, so it trumps the
// --driver flag. This behavior exists for backwards-compatibilty.
experimentalAPI, _ := cmdFleet.PersistentFlags().GetBool("experimental-api")
endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
if !experimentalAPI {
// Additionally, if the user set --experimental-api=false and did
// not change the value of --endpoint, they likely want to use the
// old default value.
if endPoint == defaultEndpoint {
endPoint = "http://127.0.0.1:2379,http://127.0.0.1:4001"
}
}
return endPoint
}

func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
var dial func(string, string) (net.Conn, error)
SSHUserName, _ := cmdFleet.PersistentFlags().GetString("ssh-username")
Expand Down Expand Up @@ -469,9 +472,8 @@ func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
TLSClientConfig: tlsConfig,
}

endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
eCfg := etcd.Config{
Endpoints: strings.Split(endPoint, ","),
Endpoints: strings.Split(getEndpoint(), ","),
Transport: trans,
HeaderTimeoutPerRequest: getRequestTimeoutFlag(cCmd),
}
Expand Down

0 comments on commit 85d1d29

Please sign in to comment.