Switch to using the official etcd health check.

This commit is contained in:
Brendan Burns
2015-06-23 21:47:24 -07:00
parent f4e7b5480d
commit f4e97be78e
5 changed files with 72 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package tools
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@@ -712,3 +713,19 @@ func NewEtcdClientStartServerIfNecessary(server string) (EtcdClient, error) {
servers := []string{server}
return etcd.NewClient(servers), nil
}
type etcdHealth struct {
// Note this has to be public so the json library can modify it.
Health string `json:health`
}
func EtcdHealthCheck(data []byte) error {
obj := etcdHealth{}
if err := json.Unmarshal(data, &obj); err != nil {
return err
}
if obj.Health != "true" {
return fmt.Errorf("Unhealthy status: %s", obj.Health)
}
return nil
}