Merge pull request #10301 from daehyeok/docker_version_10282
Validate minimum docker versionpull/10337/head
commit
14c499b00f
|
@ -36,6 +36,9 @@ func (f *FailFastError) Error() string {
|
|||
// ErrWindowsContainers is thrown when docker been configured to run windows containers instead of Linux
|
||||
var ErrWindowsContainers = &FailFastError{errors.New("docker container type is windows")}
|
||||
|
||||
// ErrMinDockerVersion is thrown when docker version is less than minimum requited by Minikube
|
||||
var ErrMinDockerVersion = &FailFastError{errors.New("docker version is less than the minimum required")}
|
||||
|
||||
// ErrCPUCountLimit is thrown when docker daemon doesn't have enough CPUs for the requested container
|
||||
var ErrCPUCountLimit = &FailFastError{errors.New("not enough CPUs is available for container")}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -37,6 +38,7 @@ import (
|
|||
)
|
||||
|
||||
var docURL = "https://minikube.sigs.k8s.io/docs/drivers/docker/"
|
||||
var minDockerVersion = []int{18, 9, 0}
|
||||
|
||||
func init() {
|
||||
if err := registry.Register(registry.DriverDef{
|
||||
|
@ -113,8 +115,8 @@ func status() registry.State {
|
|||
}
|
||||
|
||||
klog.Infof("docker version: %s", o)
|
||||
if strings.Contains(string(o), "windows-") {
|
||||
return registry.State{Reason: "PROVIDER_DOCKER_WINDOWS_CONTAINERS", Error: oci.ErrWindowsContainers, Installed: true, Healthy: false, Fix: "Change container type to \"linux\" in Docker Desktop settings", Doc: docURL + "#verify-docker-container-type-is-linux"}
|
||||
if s := checkDockerVersion(string(o)); s.Error != nil {
|
||||
return s
|
||||
}
|
||||
|
||||
si, err := oci.CachedDaemonInfo("docker")
|
||||
|
@ -130,6 +132,75 @@ func status() registry.State {
|
|||
return checkNeedsImprovement()
|
||||
}
|
||||
|
||||
func checkDockerVersion(o string) registry.State {
|
||||
parts := strings.SplitN(o, "-", 2)
|
||||
if len(parts) != 2 {
|
||||
return registry.State{
|
||||
Reason: "PROVIDER_DOCKER_VERSION_PARSING_FAILED",
|
||||
Error: errors.Errorf("expected version string format is \"{{.Server.Os}}-{{.Server.Version}}\". but got %s", o),
|
||||
Installed: true,
|
||||
Healthy: false,
|
||||
Doc: docURL,
|
||||
}
|
||||
}
|
||||
|
||||
if parts[0] == "windows" {
|
||||
return registry.State{
|
||||
Reason: "PROVIDER_DOCKER_WINDOWS_CONTAINERS",
|
||||
Error: oci.ErrWindowsContainers,
|
||||
Installed: true,
|
||||
Healthy: false,
|
||||
Fix: "Change container type to \"linux\" in Docker Desktop settings",
|
||||
Doc: docURL + "#verify-docker-container-type-is-linux",
|
||||
}
|
||||
}
|
||||
|
||||
p := strings.SplitN(parts[1], ".", 3)
|
||||
switch l := len(p); l {
|
||||
case 2:
|
||||
p = append(p, "0") // patch version not found
|
||||
case 3:
|
||||
//remove postfix string for unstable(test/nightly) channel. https://docs.docker.com/engine/install/
|
||||
p[2] = strings.SplitN(p[2], "-", 2)[0]
|
||||
default:
|
||||
return registry.State{
|
||||
Reason: "PROVIDER_DOCKER_VERSION_PARSING_FAILED",
|
||||
Error: errors.Errorf("expected version format is \"<year>.<month>.{patch}\". but got %s", parts[1]),
|
||||
Installed: true,
|
||||
Healthy: false,
|
||||
Doc: docURL,
|
||||
}
|
||||
}
|
||||
|
||||
for i, s := range p {
|
||||
k, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return registry.State{
|
||||
Reason: "PROVIDER_DOCKER_VERSION_PARSING_FAILED",
|
||||
Error: errors.Wrap(err, "docker version"),
|
||||
Installed: true,
|
||||
Healthy: false,
|
||||
Doc: docURL,
|
||||
}
|
||||
}
|
||||
|
||||
if k > minDockerVersion[i] {
|
||||
return registry.State{Installed: true, Healthy: true, Error: nil}
|
||||
} else if k < minDockerVersion[i] {
|
||||
return registry.State{
|
||||
Reason: "PROVIDER_DOCKER_VERSION_LOW",
|
||||
Error: oci.ErrMinDockerVersion,
|
||||
Installed: true,
|
||||
Healthy: false,
|
||||
NeedsImprovement: true,
|
||||
Fix: fmt.Sprintf("Upgrade %s to a newer version (Minimum supproted version is %2d.%2d.%d)", driver.FullName(driver.Docker), minDockerVersion[0], minDockerVersion[1], minDockerVersion[2]),
|
||||
Doc: docURL + "#requirements"}
|
||||
}
|
||||
}
|
||||
|
||||
return registry.State{Installed: true, Healthy: true, Error: nil}
|
||||
}
|
||||
|
||||
// checkNeedsImprovement if overlay mod is installed on a system
|
||||
func checkNeedsImprovement() registry.State {
|
||||
if runtime.GOOS == "linux" {
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// +build darwin
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
version, expect string
|
||||
}
|
||||
|
||||
func appendVersionVariations(tc []testCase, v []int, reason string) []testCase {
|
||||
appendedTc := append(tc, testCase{
|
||||
version: fmt.Sprintf("linux-%02d.%02d", v[0], v[1]),
|
||||
expect: reason,
|
||||
})
|
||||
|
||||
// postfix string for unstable channel or patch. https://docs.docker.com/engine/install/
|
||||
patchPostFix := "20180720214833-f61e0f7"
|
||||
|
||||
vs := fmt.Sprintf("%02d.%02d.%d", v[0], v[1], v[2])
|
||||
appendedTc = append(appendedTc, []testCase{
|
||||
{
|
||||
version: fmt.Sprintf("linux-%s", vs),
|
||||
expect: reason,
|
||||
},
|
||||
{
|
||||
version: fmt.Sprintf("linux-%s-%s", vs, patchPostFix),
|
||||
expect: reason,
|
||||
},
|
||||
}...,
|
||||
)
|
||||
|
||||
return appendedTc
|
||||
}
|
||||
|
||||
func TestCheckDockerVersion(t *testing.T) {
|
||||
tc := []testCase{
|
||||
{
|
||||
version: "windows-20.0.1",
|
||||
expect: "PROVIDER_DOCKER_WINDOWS_CONTAINERS",
|
||||
},
|
||||
{
|
||||
version: fmt.Sprintf("linux-%02d.%02d", minDockerVersion[0], minDockerVersion[1]),
|
||||
expect: "",
|
||||
},
|
||||
{
|
||||
version: fmt.Sprintf("linux-%02d.%02d.%02d", minDockerVersion[0], minDockerVersion[1], minDockerVersion[2]),
|
||||
expect: "",
|
||||
},
|
||||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
v := make([]int, 3)
|
||||
copy(v, minDockerVersion)
|
||||
|
||||
v[i] = minDockerVersion[i] + 1
|
||||
tc = appendVersionVariations(tc, v, "")
|
||||
|
||||
v[i] = minDockerVersion[i] - 1
|
||||
if v[2] < 0 {
|
||||
// skip test if patch version is negative number.
|
||||
continue
|
||||
}
|
||||
tc = appendVersionVariations(tc, v, "PROVIDER_DOCKER_VERSION_LOW")
|
||||
}
|
||||
|
||||
for _, c := range tc {
|
||||
t.Run("checkDockerVersion test", func(t *testing.T) {
|
||||
s := checkDockerVersion(c.version)
|
||||
if c.expect != s.Reason {
|
||||
t.Errorf("Error %v expected. but got %q. (version string : %s)", c.expect, s.Reason, c.version)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
## Requirements
|
||||
|
||||
- [Install Docker](https://hub.docker.com/search?q=&type=edition&offering=community&sort=updated_at&order=desc)
|
||||
- [Install Docker](https://hub.docker.com/search?q=&type=edition&offering=community&sort=updated_at&order=desc) 18.09 or higher
|
||||
- amd64 system.
|
||||
|
||||
## Usage
|
||||
|
|
Loading…
Reference in New Issue