mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #99647 from neolit123/1.21-remove-cgroup-driver-detection
kubeadm: remove the cgroup driver detection for docker
This commit is contained in:
commit
d6b408f748
@ -24,14 +24,12 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
kubeletconfig "k8s.io/kubelet/config/v1beta1"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"
|
||||
utilsexec "k8s.io/utils/exec"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -201,20 +199,6 @@ func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubead
|
||||
// There is no way to determine if the user has set this or not, given the field is a non-pointer.
|
||||
kc.config.RotateCertificates = kubeletRotateCertificates
|
||||
|
||||
// TODO: Conditionally set CgroupDriver to either `systemd` or `cgroupfs` for CRI other than Docker
|
||||
if nodeRegOpts.CRISocket == constants.DefaultDockerCRISocket {
|
||||
driver, err := kubeadmutil.GetCgroupDriverDocker(utilsexec.New())
|
||||
if err != nil {
|
||||
klog.Warningf("cannot automatically set CgroupDriver when starting the Kubelet: %v", err)
|
||||
} else {
|
||||
// if we can parse the right cgroup driver from docker info,
|
||||
// we should always override CgroupDriver here no matter user specifies this value explicitly or not
|
||||
if kc.config.CgroupDriver != "" && kc.config.CgroupDriver != driver {
|
||||
klog.Warningf("detected %q as the Docker cgroup driver, the provided value %q in %q will be overrided", driver, kc.config.CgroupDriver, kind)
|
||||
}
|
||||
kc.config.CgroupDriver = driver
|
||||
}
|
||||
}
|
||||
if len(kc.config.CgroupDriver) == 0 {
|
||||
klog.V(1).Infof("the value of KubeletConfiguration.cgroupDriver is empty; setting it to %q", constants.CgroupDriverSystemd)
|
||||
kc.config.CgroupDriver = constants.CgroupDriverSystemd
|
||||
|
@ -398,8 +398,6 @@ const (
|
||||
|
||||
// CgroupDriverSystemd holds the systemd driver type
|
||||
CgroupDriverSystemd = "systemd"
|
||||
// CgroupDriverCgroupfs holds the cgroupfs driver type
|
||||
CgroupDriverCgroupfs = "cgroupfs"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -223,14 +223,6 @@ func (IsPrivilegedUserCheck) Name() string {
|
||||
return "IsPrivilegedUser"
|
||||
}
|
||||
|
||||
// IsDockerSystemdCheck verifies if Docker is setup to use systemd as the cgroup driver.
|
||||
type IsDockerSystemdCheck struct{}
|
||||
|
||||
// Name returns name for IsDockerSystemdCheck
|
||||
func (IsDockerSystemdCheck) Name() string {
|
||||
return "IsDockerSystemdCheck"
|
||||
}
|
||||
|
||||
// DirAvailableCheck checks if the given directory either does not exist, or is empty.
|
||||
type DirAvailableCheck struct {
|
||||
Path string
|
||||
@ -1020,10 +1012,6 @@ func addCommonChecks(execer utilsexec.Interface, k8sVersion string, nodeReg *kub
|
||||
if containerRuntime.IsDocker() {
|
||||
isDocker = true
|
||||
checks = append(checks, ServiceCheck{Service: "docker", CheckIfActive: true})
|
||||
// Linux only
|
||||
// TODO: support other CRIs for this check eventually
|
||||
// https://github.com/kubernetes/kubeadm/issues/874
|
||||
checks = append(checks, IsDockerSystemdCheck{})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,6 @@ package preflight
|
||||
|
||||
// This is a MacOS stub
|
||||
|
||||
// Check validates if Docker is setup to use systemd as the cgroup driver.
|
||||
// No-op for Darwin (MacOS).
|
||||
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Check number of memory required by kubeadm
|
||||
// No-op for Darwin (MacOS).
|
||||
func (mc MemCheck) Check() (warnings, errorList []error) {
|
||||
|
@ -22,28 +22,8 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
"k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
// Check validates if Docker is setup to use systemd as the cgroup driver.
|
||||
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
|
||||
driver, err := kubeadmutil.GetCgroupDriverDocker(exec.New())
|
||||
if err != nil {
|
||||
return nil, []error{err}
|
||||
}
|
||||
if driver != constants.CgroupDriverSystemd {
|
||||
err = errors.Errorf("detected %q as the Docker cgroup driver. "+
|
||||
"The recommended driver is %q. "+
|
||||
"Please follow the guide at https://kubernetes.io/docs/setup/cri/",
|
||||
driver,
|
||||
constants.CgroupDriverSystemd)
|
||||
return []error{err}, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Check number of memory required by kubeadm
|
||||
func (mc MemCheck) Check() (warnings, errorList []error) {
|
||||
info := syscall.Sysinfo_t{}
|
||||
|
@ -49,12 +49,6 @@ func (ipuc IsPrivilegedUserCheck) Check() (warnings, errorList []error) {
|
||||
return nil, []error{errors.New("user is not running as administrator")}
|
||||
}
|
||||
|
||||
// Check validates if Docker is setup to use systemd as the cgroup driver.
|
||||
// No-op for Windows.
|
||||
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Check number of memory required by kubeadm
|
||||
// No-op for Windows.
|
||||
func (mc MemCheck) Check() (warnings, errorList []error) {
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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 util
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
utilsexec "k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
// TODO: add support for detecting the cgroup driver for CRI other than
|
||||
// Docker. Currently only Docker driver detection is supported:
|
||||
// Discussion:
|
||||
// https://github.com/kubernetes/kubeadm/issues/844
|
||||
|
||||
// GetCgroupDriverDocker runs 'docker info -f "{{.CgroupDriver}}"' to obtain the docker cgroup driver
|
||||
func GetCgroupDriverDocker(execer utilsexec.Interface) (string, error) {
|
||||
driver, err := callDockerInfo(execer)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSuffix(driver, "\n"), nil
|
||||
}
|
||||
|
||||
func callDockerInfo(execer utilsexec.Interface) (string, error) {
|
||||
out, err := execer.Command("docker", "info", "-f", "{{.CgroupDriver}}").Output()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "cannot execute 'docker info -f {{.CgroupDriver}}'")
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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 util
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetCgroupDriverDocker(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
driver string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
name: "valid: value is 'cgroupfs'",
|
||||
driver: `cgroupfs`,
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
name: "valid: value is 'systemd'",
|
||||
driver: `systemd`,
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
name: "invalid: empty 'Cgroup Driver' value",
|
||||
driver: ``,
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "invalid: unknown 'Cgroup Driver' value",
|
||||
driver: `invalid-value`,
|
||||
expectedError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := tc.driver != constants.CgroupDriverCgroupfs && tc.driver != constants.CgroupDriverSystemd
|
||||
if result != tc.expectedError {
|
||||
t.Fatalf("expected error: %v, saw: %v", tc.expectedError, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user