Skip to content

Commit a1cc48b

Browse files
authored
Merge pull request kubernetes#73837 from neolit123/preflight-docker-cgroup
kubeadm: add a preflight check for Docker and cgroup driver
2 parents 40a4c1f + 3b3b79f commit a1cc48b

File tree

6 files changed

+105
-2
lines changed

6 files changed

+105
-2
lines changed

cmd/kubeadm/app/preflight/BUILD

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ go_library(
1010
name = "go_default_library",
1111
srcs = [
1212
"checks.go",
13+
"checks_darwin.go",
14+
"checks_linux.go",
1315
"checks_unix.go",
1416
"checks_windows.go",
1517
"utils.go",
@@ -33,7 +35,12 @@ go_library(
3335
"//vendor/github.com/pkg/errors:go_default_library",
3436
"//vendor/k8s.io/klog:go_default_library",
3537
"//vendor/k8s.io/utils/exec:go_default_library",
36-
],
38+
] + select({
39+
"@io_bazel_rules_go//go/platform:linux": [
40+
"//cmd/kubeadm/app/util:go_default_library",
41+
],
42+
"//conditions:default": [],
43+
}),
3744
)
3845

3946
go_test(

cmd/kubeadm/app/preflight/checks.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ func (IsPrivilegedUserCheck) Name() string {
226226
return "IsPrivilegedUser"
227227
}
228228

229+
// IsDockerSystemdCheck verifies if Docker is setup to use systemd as the cgroup driver.
230+
type IsDockerSystemdCheck struct{}
231+
232+
// Name returns name for IsDockerSystemdCheck
233+
func (IsDockerSystemdCheck) Name() string {
234+
return "IsDockerSystemdCheck"
235+
}
236+
229237
// DirAvailableCheck checks if the given directory either does not exist, or is empty.
230238
type DirAvailableCheck struct {
231239
Path string
@@ -998,6 +1006,10 @@ func addCommonChecks(execer utilsexec.Interface, cfg kubeadmapi.CommonConfigurat
9981006
if containerRuntime.IsDocker() {
9991007
isDocker = true
10001008
checks = append(checks, ServiceCheck{Service: "docker", CheckIfActive: true})
1009+
// Linux only
1010+
// TODO: support other CRIs for this check eventually
1011+
// https://github.com/kubernetes/kubeadm/issues/874
1012+
checks = append(checks, IsDockerSystemdCheck{})
10011013
}
10021014
}
10031015

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// +build darwin
2+
3+
/*
4+
Copyright 2019 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package preflight
20+
21+
// This is a MacOS stub
22+
23+
// Check validates if Docker is setup to use systemd as the cgroup driver.
24+
// No-op for Darwin (MacOS).
25+
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
26+
return nil, nil
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// +build linux
2+
3+
/*
4+
Copyright 2019 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package preflight
20+
21+
import (
22+
"github.com/pkg/errors"
23+
"k8s.io/kubernetes/cmd/kubeadm/app/util"
24+
"k8s.io/utils/exec"
25+
)
26+
27+
// Check validates if Docker is setup to use systemd as the cgroup driver.
28+
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
29+
warnings = []error{}
30+
driver, err := util.GetCgroupDriverDocker(exec.New())
31+
if err != nil {
32+
errorList = append(errorList, err)
33+
return nil, errorList
34+
}
35+
if driver != util.CgroupDriverSystemd {
36+
err = errors.Errorf("detected %q as the Docker cgroup driver. "+
37+
"The recommended driver is %q. "+
38+
"Please follow the guide at https://kubernetes.io/docs/setup/cri/",
39+
driver,
40+
util.CgroupDriverSystemd)
41+
warnings = append(warnings, err)
42+
}
43+
return warnings, nil
44+
}

cmd/kubeadm/app/preflight/checks_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ func (ipuc IsPrivilegedUserCheck) Check() (warnings, errorList []error) {
4343

4444
return nil, errorList
4545
}
46+
47+
// Check validates if Docker is setup to use systemd as the cgroup driver.
48+
// No-op for Windows.
49+
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
50+
return nil, nil
51+
}

cmd/kubeadm/app/util/cgroupdriver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ import (
2424
utilsexec "k8s.io/utils/exec"
2525
)
2626

27+
const (
28+
// CgroupDriverSystemd holds the systemd driver type
29+
CgroupDriverSystemd = "systemd"
30+
// CgroupDriverCgroupfs holds the cgroupfs driver type
31+
CgroupDriverCgroupfs = "cgroupfs"
32+
)
33+
2734
// TODO: add support for detecting the cgroup driver for CRI other than
2835
// Docker. Currently only Docker driver detection is supported:
2936
// Discussion:
@@ -39,7 +46,7 @@ func GetCgroupDriverDocker(execer utilsexec.Interface) (string, error) {
3946
}
4047

4148
func validateCgroupDriver(driver string) error {
42-
if driver != "cgroupfs" && driver != "systemd" {
49+
if driver != CgroupDriverCgroupfs && driver != CgroupDriverSystemd {
4350
return errors.Errorf("unknown cgroup driver %q", driver)
4451
}
4552
return nil

0 commit comments

Comments
 (0)