Skip to content

Commit 881d72b

Browse files
authored
Merge pull request #15646 from spowelljr/warnDockerVersion
Add check for Docker Desktop 4.16.0
2 parents 7cf876c + c27da1c commit 881d72b

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

pkg/minikube/registry/drvs/docker/docker.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func status() (retState registry.State) {
102102
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second)
103103
defer cancel()
104104

105-
cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}")
105+
cmd := exec.CommandContext(ctx, oci.Docker, "version", "--format", "{{.Server.Os}}-{{.Server.Version}}:{{.Server.Platform.Name}}")
106106
o, err := cmd.Output()
107107
if err != nil {
108108
reason := ""
@@ -135,9 +135,15 @@ func status() (retState registry.State) {
135135
}
136136
}()
137137

138+
versions := strings.Split(string(o), ":")
139+
dockerEngineVersion := versions[0]
140+
dockerPlatformVersion := versions[1]
138141
klog.Infof("docker version: %s", o)
139142
if !viper.GetBool("force") {
140-
s := checkDockerVersion(strings.TrimSpace(string(o))) // remove '\n' from o at the end
143+
if s := checkDockerDesktopVersion(dockerPlatformVersion); s != nil {
144+
return *s
145+
}
146+
s := checkDockerEngineVersion(strings.TrimSpace(dockerEngineVersion)) // remove '\n' from o at the end
141147
if s.Error != nil {
142148
return s
143149
}
@@ -159,7 +165,7 @@ func status() (retState registry.State) {
159165
return checkNeedsImprovement()
160166
}
161167

162-
func checkDockerVersion(o string) registry.State {
168+
func checkDockerEngineVersion(o string) registry.State {
163169
parts := strings.SplitN(o, "-", 2)
164170
if len(parts) != 2 {
165171
return registry.State{
@@ -240,6 +246,27 @@ func checkDockerVersion(o string) registry.State {
240246
Doc: docURL + "#requirements"}
241247
}
242248

249+
func checkDockerDesktopVersion(version string) *registry.State {
250+
fields := strings.Fields(version)
251+
if len(fields) < 3 || fields[0] != "Docker" || fields[1] != "Desktop" {
252+
return nil
253+
}
254+
currSemver, err := semver.Parse(fields[2])
255+
if err != nil {
256+
return nil
257+
}
258+
if currSemver.EQ(semver.MustParse("4.16.0")) {
259+
return &registry.State{
260+
Reason: "PROVIDER_DOCKER_DESKTOP_VERSION_BAD",
261+
Running: true,
262+
Error: errors.New("Docker Desktop 4.16.0 has a regression that prevents minikube from starting"),
263+
Installed: true,
264+
Fix: "Update Docker Desktop to 4.16.1 or greater",
265+
}
266+
}
267+
return nil
268+
}
269+
243270
// checkNeedsImprovement if overlay mod is installed on a system
244271
func checkNeedsImprovement() registry.State {
245272
if runtime.GOOS == "linux" {

pkg/minikube/registry/drvs/docker/docker_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func stringToIntSlice(t *testing.T, s string) []int {
6464
return []int{int(sem.Major), int(sem.Minor), int(sem.Patch)}
6565
}
6666

67-
func TestCheckDockerVersion(t *testing.T) {
67+
func TestCheckDockerEngineVersion(t *testing.T) {
6868
recParts := stringToIntSlice(t, recommendedDockerVersion)
6969
minParts := stringToIntSlice(t, minDockerVersion)
7070

@@ -135,8 +135,8 @@ func TestCheckDockerVersion(t *testing.T) {
135135
}...)
136136

137137
for _, c := range tc {
138-
t.Run("checkDockerVersion test", func(t *testing.T) {
139-
s := checkDockerVersion(c.version)
138+
t.Run("checkDockerEngineVersion test", func(t *testing.T) {
139+
s := checkDockerEngineVersion(c.version)
140140
if s.Error != nil {
141141
if c.expect != s.Reason {
142142
t.Errorf("Error %v expected. but got %q. (version string : %s)", c.expect, s.Reason, c.version)
@@ -150,3 +150,23 @@ func TestCheckDockerVersion(t *testing.T) {
150150
})
151151
}
152152
}
153+
154+
func TestCheckDockerDesktopVersion(t *testing.T) {
155+
tests := []struct {
156+
input string
157+
shouldReturnState bool
158+
}{
159+
{"Docker Desktop", false},
160+
{"Cat Desktop 4.16.0", false},
161+
{"Docker Playground 4.16.0", false},
162+
{"Docker Desktop 4.15.0", false},
163+
{"Docker Desktop 4.16.0", true},
164+
{" Docker Desktop 4.16.0 ", true},
165+
}
166+
for _, tt := range tests {
167+
state := checkDockerDesktopVersion(tt.input)
168+
if (state == nil && tt.shouldReturnState) || (state != nil && !tt.shouldReturnState) {
169+
t.Errorf("checkDockerDesktopVersion(%q) = %v; expected shouldRetunState = %t", tt.input, state, tt.shouldReturnState)
170+
}
171+
}
172+
}

0 commit comments

Comments
 (0)