Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak docker desktop validation check for newer versions #1023

Merged
merged 3 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func commonValidation(ctx context.Context, clusterConfigFile string) (*v1alpha1.
return nil, fmt.Errorf("failed to validate docker: %v", err)
}
if runtime.GOOS == "darwin" {
err = validations.CheckDockerDesktopVersion(ctx)
err = validations.CheckDockerDesktopVersion(ctx, docker)
if err != nil {
return nil, fmt.Errorf("failed to validate docker desktop: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions docs/content/en/docs/getting-started/install/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This will let you create a cluster in multiple providers for local development o

> **_NOTE:_** If you are using Ubuntu use the [Docker CE](https://docs.docker.com/engine/install/ubuntu/) installation instructions to install Docker and not the Snap installation.

> **_NOTE:_** If you are using Mac OS Docker Desktop 4.4.2 or newer `"deprecatedCgroupv1": true` must be set in `~/Library/Group\ Containers/group.com.docker/settings.json`.

### Install EKS Anywhere CLI tools

#### Via Homebrew (macOS and Linux)
Expand Down
15 changes: 15 additions & 0 deletions docs/content/en/docs/tasks/troubleshoot/_troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ Ensure you are running Docker 20.x.x for example:
Docker version 20.10.6, build 370c289
```

### Minimum requirements for docker version have not been met on Mac OS
```
Error: EKS Anywhere does not support Docker desktop versions between 4.3.0 and 4.4.1 on macOS
```
```
Error: EKS Anywhere requires Docker desktop to be configured to use CGroups v1. Please set `deprecatedCgroupv1:true` in your `~/Library/Group\\ Containers/group.com.docker/settings.json` file
```
Ensure you are running Docker Desktop 4.4.2 or newer and have set `"deprecatedCgroupv1": true` in your settings.json file
```
% defaults read /Applications/Docker.app/Contents/Info.plist CFBundleShortVersionString
4.42
% docker info --format '{{json .CgroupVersion}}'
"1"
```

### ECR access denied

```
Expand Down
14 changes: 14 additions & 0 deletions pkg/executables/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ func (d *Docker) AllocatedMemory(ctx context.Context) (uint64, error) {
return strconv.ParseUint(totalMemory, 10, 64)
}

func (d *Docker) CgroupVersion(ctx context.Context) (int, error) {
cmdOutput, err := d.Execute(ctx, "info", "--format", "'{{json .CgroupVersion}}'")
if err != nil {
return 0, fmt.Errorf("please check if docker is installed and running %v", err)
}
cgroupVersion := strings.TrimSpace(cmdOutput.String())
cgroupVersion = strings.Trim(cgroupVersion, "\"'")
version, err := strconv.Atoi(cgroupVersion)
if err != nil {
return 0, err
}
return version, nil
}

func (d *Docker) TagImage(ctx context.Context, image string, endpoint string) error {
localImage := strings.ReplaceAll(image, defaultRegistry, endpoint)
logger.Info("Tagging image", "image", image, "local image", localImage)
Expand Down
19 changes: 19 additions & 0 deletions pkg/executables/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,22 @@ func TestDockerAllocatedMemory(t *testing.T) {
t.Fatalf("Docker.AllocatedMemory() error = %v, want %v", err, mem)
}
}

func TestDockerCgroupVersion(t *testing.T) {
version := "'\"1\"'\n"
wantVersion := 1

ctx := context.Background()
mockCtrl := gomock.NewController(t)

executable := mockexecutables.NewMockExecutable(mockCtrl)
executable.EXPECT().Execute(ctx, "info", "--format", "'{{json .CgroupVersion}}'").Return(*bytes.NewBufferString(version), nil)
d := executables.NewDocker(executable)
cgroupVersion, err := d.CgroupVersion(ctx)
if err != nil {
t.Fatalf("Docker.AllocatedMemory() error = %v, want %v", err, cgroupVersion)
}
if !reflect.DeepEqual(cgroupVersion, wantVersion) {
t.Fatalf("Docker.Version() version = %v, want %v", cgroupVersion, wantVersion)
}
}
52 changes: 44 additions & 8 deletions pkg/validations/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/semver"
)

const (
recommendedTotalMemory = 6200000000
requiredMajorVersion = 20
unsupportedMinorVersion = "4.3"
recommendedTotalMemory = 6200000000
requiredMajorVersion = 20
minUnsupportedVersion = "4.3.0"
minSupportedWithSettingVersion = "4.4.2"
)

type DockerExecutable interface {
Version(ctx context.Context) (int, error)
AllocatedMemory(ctx context.Context) (uint64, error)
CgroupVersion(ctx context.Context) (int, error)
}

func CheckMinimumDockerVersion(ctx context.Context, dockerExecutable DockerExecutable) error {
Expand All @@ -43,7 +46,7 @@ func CheckDockerAllocatedMemory(ctx context.Context, dockerExecutable DockerExec
}
}

func CheckDockerDesktopVersion(ctx context.Context) error {
func CheckDockerDesktopVersion(ctx context.Context, dockerExecutable DockerExecutable) error {
dockerDesktopInfoPath := "/Applications/Docker.app/Contents/Info.plist"
if _, err := os.Stat(dockerDesktopInfoPath); err != nil {
return fmt.Errorf("unable to find Docker Desktop info list")
Expand All @@ -53,10 +56,43 @@ func CheckDockerDesktopVersion(ctx context.Context) error {
if err != nil {
return err
}
dockerDesktopVersion := strings.TrimSpace(string(stdout))
dockerDesktopMinorRelease := dockerDesktopVersion[:strings.LastIndex(dockerDesktopVersion, ".")]
if dockerDesktopMinorRelease >= unsupportedMinorVersion {
return fmt.Errorf("EKS Anywhere does not support Docker desktop version 4.3.0 or greater on macOS")

return ValidateDockerDesktopVersion(ctx, dockerExecutable, string(stdout))
}

func ValidateDockerDesktopVersion(ctx context.Context, dockerExecutable DockerExecutable, dockerDesktopVersion string) error {
minUnsupportedSemVer, err := semver.New(minUnsupportedVersion)
if err != nil {
return err
}

minSupportWithSettingSemVer, err := semver.New(minSupportedWithSettingVersion)
if err != nil {
return err
}

dockerDesktopSemVer, err := semver.New(strings.TrimSpace(dockerDesktopVersion))
if err != nil {
return err
}

if dockerDesktopSemVer.LessThan(minUnsupportedSemVer) {
// Older versions of docker desktop are supported as is
return nil
}

if dockerDesktopSemVer.LessThan(minSupportWithSettingSemVer) {
return fmt.Errorf("EKS Anywhere does not support Docker desktop versions between 4.3.0 and 4.4.1 on macOS")
}

cgroupVersion, err := dockerExecutable.CgroupVersion(ctx)
if err != nil {
return err
}

if cgroupVersion != 1 {
return fmt.Errorf("EKS Anywhere requires Docker desktop to be configured to use CGroups v1. " +
"Please set `deprecatedCgroupv1:true` in your `~/Library/Group\\ Containers/group.com.docker/settings.json` file")
}

return nil
Expand Down
77 changes: 77 additions & 0 deletions pkg/validations/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,80 @@ func TestValidateDockerVersion(t *testing.T) {
})
}
}

func TestCheckDockerDesktopVersion(t *testing.T) {
ctx := context.Background()

tests := []struct {
name string
wantErr error
dockerDesktopVersion string
cgroupVersion int
needsCgroup bool
}{
{
name: "SuccessDockerDesktopVersion42",
dockerDesktopVersion: "4.2.0",
wantErr: nil,
cgroupVersion: 1,
needsCgroup: false,
},
{
name: "FailureDockerDesktopVersion430",
dockerDesktopVersion: "4.3.0",
wantErr: fmt.Errorf("EKS Anywhere does not support Docker desktop versions between 4.3.0 and 4.4.1 on macOS"),
cgroupVersion: 2,
needsCgroup: false,
},
{
name: "FailureDockerDesktopVersion440",
dockerDesktopVersion: "4.4.0",
wantErr: fmt.Errorf("EKS Anywhere does not support Docker desktop versions between 4.3.0 and 4.4.1 on macOS"),
cgroupVersion: 2,
needsCgroup: false,
},
{
name: "FailureDockerDesktopVersion440",
dockerDesktopVersion: "4.4.1",
wantErr: fmt.Errorf("EKS Anywhere does not support Docker desktop versions between 4.3.0 and 4.4.1 on macOS"),
cgroupVersion: 2,
needsCgroup: false,
},
{
name: "SuccessDockerDesktopVersion442",
dockerDesktopVersion: "4.4.2",
wantErr: nil,
cgroupVersion: 1,
needsCgroup: true,
},
{
name: "FailureDockerDesktopVersion442",
dockerDesktopVersion: "4.4.2",
wantErr: fmt.Errorf("EKS Anywhere requires Docker desktop to be configured to use CGroups v1. " +
"Please set `deprecatedCgroupv1:true` in your `~/Library/Group\\ Containers/group.com.docker/settings.json` file"),
cgroupVersion: 2,
needsCgroup: true,
},
{
name: "SuccessDockerDesktopVersion450",
dockerDesktopVersion: "4.5.0",
wantErr: nil,
cgroupVersion: 1,
needsCgroup: true,
},
}

for _, tc := range tests {
t.Run(tc.name, func(tt *testing.T) {
mockCtrl := gomock.NewController(t)
dockerExecutableMock := mocks.NewMockDockerExecutable(mockCtrl)
if tc.needsCgroup {
dockerExecutableMock.EXPECT().CgroupVersion(ctx).Return(tc.cgroupVersion, tc.wantErr)
}
err := validations.ValidateDockerDesktopVersion(ctx, dockerExecutableMock, tc.dockerDesktopVersion)
if err != nil && err.Error() != tc.wantErr.Error() {
t.Errorf("%v got = %v, \nwant %v", tc.name, err, tc.wantErr)
}
})
}
}
15 changes: 15 additions & 0 deletions pkg/validations/mocks/docker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.