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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user