Fix kube2sky flakes. Fix tools.GetEtcdVersion to work with etcd > 2.0.7
This commit is contained in:
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -475,35 +474,22 @@ func (h *EtcdHelper) PrefixEtcdKey(key string) string {
|
||||
return path.Join("/", h.PathPrefix, key)
|
||||
}
|
||||
|
||||
// GetEtcdVersion performs a version check against the provided Etcd server, returning a triplet
|
||||
// of the release version, internal version, and error (if any).
|
||||
func GetEtcdVersion(host string) (releaseVersion, internalVersion string, err error) {
|
||||
// GetEtcdVersion performs a version check against the provided Etcd server,
|
||||
// returning the string response, and error (if any).
|
||||
func GetEtcdVersion(host string) (string, error) {
|
||||
response, err := http.Get(host + "/version")
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Unsuccessful response from server: %v", err)
|
||||
}
|
||||
versionBytes, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var dat map[string]interface{}
|
||||
if err := json.Unmarshal(body, &dat); err != nil {
|
||||
return "", "", fmt.Errorf("unknown server: %s", string(body))
|
||||
}
|
||||
if obj := dat["releaseVersion"]; obj != nil {
|
||||
if s, ok := obj.(string); ok {
|
||||
releaseVersion = s
|
||||
}
|
||||
}
|
||||
if obj := dat["internalVersion"]; obj != nil {
|
||||
if s, ok := obj.(string); ok {
|
||||
internalVersion = s
|
||||
}
|
||||
}
|
||||
return
|
||||
return string(versionBytes), nil
|
||||
}
|
||||
|
||||
func startEtcd() (*exec.Cmd, error) {
|
||||
@@ -516,7 +502,7 @@ func startEtcd() (*exec.Cmd, error) {
|
||||
}
|
||||
|
||||
func NewEtcdClientStartServerIfNecessary(server string) (EtcdClient, error) {
|
||||
_, _, err := GetEtcdVersion(server)
|
||||
_, err := GetEtcdVersion(server)
|
||||
if err != nil {
|
||||
glog.Infof("Failed to find etcd, attempting to start.")
|
||||
_, err := startEtcd()
|
||||
|
||||
Reference in New Issue
Block a user