1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-31 14:36:32 +00:00

Accept different patches of supported docker versions

This commit is contained in:
galal-hussein
2018-04-04 22:55:26 +02:00
parent 4136d82916
commit 8350aa203c
2 changed files with 25 additions and 6 deletions

View File

@@ -9,8 +9,9 @@ import (
"io"
"io/ioutil"
"os"
"regexp"
"strings"
"github.com/coreos/go-semver/semver"
ref "github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
@@ -26,7 +27,9 @@ const (
)
var K8sDockerVersions = map[string][]string{
"1.8": {"1.12.6", "1.13.1", "17.03.2"},
"1.8": {"1.11.x", "1.12.x", "1.13.x", "17.03.x"},
"1.9": {"1.11.x", "1.12.x", "1.13.x", "17.03.x"},
"1.10": {"1.11.x", "1.12.x", "1.13.x", "17.03.x"},
}
func DoRunContainer(ctx context.Context, dClient *client.Client, imageCfg *container.Config, hostCfg *container.HostConfig, containerName string, hostname string, plane string, prsMap map[string]v3.PrivateRegistry) error {
@@ -295,10 +298,16 @@ func sliceEqualsIgnoreOrder(left, right []string) bool {
}
func IsSupportedDockerVersion(info types.Info, K8sVersion string) (bool, error) {
// Docker versions are not semver compliant since stable/edge version (17.03 and higher) so we need to check if the reported ServerVersion starts with a compatible version
dockerVersion, err := semver.NewVersion(info.ServerVersion)
if err != nil {
return false, err
}
for _, DockerVersion := range K8sDockerVersions[K8sVersion] {
DockerVersionRegexp := regexp.MustCompile("^" + DockerVersion)
if DockerVersionRegexp.MatchString(info.ServerVersion) {
supportedDockerVersion, err := convertToSemver(DockerVersion)
if err != nil {
return false, err
}
if dockerVersion.Major == supportedDockerVersion.Major && dockerVersion.Minor == supportedDockerVersion.Minor {
return true, nil
}
@@ -359,3 +368,12 @@ func GetImageRegistryConfig(image string, prsMap map[string]v3.PrivateRegistry)
}
return "", "", nil
}
func convertToSemver(version string) (*semver.Version, error) {
compVersion := strings.SplitN(version, ".", 3)
if len(compVersion) != 3 {
return nil, fmt.Errorf("The default version is not correct")
}
compVersion[2] = "0"
return semver.NewVersion(strings.Join(compVersion, "."))
}