From 85d1d292598ce6b9df291bbe33a87e15329809df Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Wed, 9 Nov 2016 12:35:56 +0100 Subject: [PATCH] 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 848d3561 ("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. --- fleetctl/fleetctl.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/fleetctl/fleetctl.go b/fleetctl/fleetctl.go index 77d4a6e79..94050708f 100644 --- a/fleetctl/fleetctl.go +++ b/fleetctl/fleetctl.go @@ -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: @@ -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") @@ -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), }