1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-28 19:31:04 +00:00

Merge pull request #479 from galal-hussein/check_version_ranges

Accept different patches of supported docker versions
This commit is contained in:
Alena Prokharchyk 2018-04-04 15:18:00 -07:00 committed by GitHub
commit e758a9805c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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, "."))
}

View File

@ -8,13 +8,14 @@ import (
"path/filepath"
"strings"
"net"
"github.com/docker/docker/client"
"github.com/rancher/rke/docker"
"github.com/rancher/rke/log"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"net"
)
const (