Use go-dockerclient's APIVersion

Use go-dockerclient's APIVersion to check the minimum required Docker
version, as it contains methods for parsing the ApiVersion response from
the Docker daemon and for comparing 2 APIVersion objects.
This commit is contained in:
Andy Goldstein
2015-04-20 13:48:18 -04:00
parent cf27de61c6
commit a0a80ea76e
6 changed files with 34 additions and 66 deletions

View File

@@ -41,6 +41,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/flushwriter"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
cadvisorApi "github.com/google/cadvisor/info/v1"
"github.com/prometheus/client_golang/prometheus"
@@ -100,7 +101,7 @@ func ListenAndServeKubeletReadOnlyServer(host HostInterface, address net.IP, por
type HostInterface interface {
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
GetDockerVersion() ([]uint, error)
GetDockerVersion() (docker.APIVersion, error)
GetCachedMachineInfo() (*cadvisorApi.MachineInfo, error)
GetPods() []*api.Pod
GetPodByName(namespace, name string) (*api.Pod, bool)
@@ -159,31 +160,18 @@ func (s *Server) error(w http.ResponseWriter, err error) {
http.Error(w, msg, http.StatusInternalServerError)
}
func isValidDockerVersion(ver []uint) (bool, string) {
minAllowedVersion := []uint{1, 15}
for i := 0; i < len(ver) && i < len(minAllowedVersion); i++ {
if ver[i] != minAllowedVersion[i] {
if ver[i] < minAllowedVersion[i] {
versions := make([]string, len(ver))
for i, v := range ver {
versions[i] = fmt.Sprint(v)
}
return false, strings.Join(versions, ".")
}
return true, ""
}
}
return true, ""
func isValidDockerVersion(ver docker.APIVersion) bool {
minAllowedVersion, _ := docker.NewAPIVersion("1.15")
return ver.GreaterThanOrEqualTo(minAllowedVersion)
}
func (s *Server) dockerHealthCheck(req *http.Request) error {
versions, err := s.host.GetDockerVersion()
version, err := s.host.GetDockerVersion()
if err != nil {
return errors.New("unknown Docker version")
}
valid, version := isValidDockerVersion(versions)
if !valid {
return fmt.Errorf("Docker version is too old (%v)", version)
if !isValidDockerVersion(version) {
return fmt.Errorf("Docker version is too old (%v)", version.String())
}
return nil
}