mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
kubeadm: move cgroupDriver defaulting to componentconfigs/kubelet.go#Default()
Signed-off-by: pacoxu <paco.xu@daocloud.io>
This commit is contained in:
parent
1d38084930
commit
2fdbfd8a27
@ -37,7 +37,6 @@ import (
|
||||
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/init"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
|
||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
||||
@ -337,12 +336,6 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// For new clusters we want to set the kubelet cgroup driver to "systemd" unless the user is explicit about it.
|
||||
// Currently this cannot be as part of the kubelet defaulting (Default()) because the function is called for
|
||||
// upgrades too, which can break existing nodes after a kubelet restart.
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
componentconfigs.MutateCgroupDriver(&cfg.ClusterConfiguration)
|
||||
|
||||
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(options.ignorePreflightErrors, cfg.NodeRegistration.IgnorePreflightErrors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -91,10 +91,6 @@ func runPlan(flags *planFlags, args []string) error {
|
||||
return errors.WithMessage(err, "[upgrade/versions] FATAL")
|
||||
}
|
||||
|
||||
// Warn if the kubelet component config is missing an explicit 'cgroupDriver'.
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
componentconfigs.WarnCgroupDriver(&cfg.ClusterConfiguration)
|
||||
|
||||
// No upgrades available
|
||||
if len(availUpgrades) == 0 {
|
||||
klog.V(1).Infoln("[upgrade/plan] Awesome, you're up-to-date! Enjoy!")
|
||||
|
@ -17,10 +17,8 @@ limitations under the License.
|
||||
package componentconfigs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog/v2"
|
||||
@ -217,6 +215,10 @@ func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubead
|
||||
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
|
||||
}
|
||||
|
||||
ok, err := isServiceActive("systemd-resolved")
|
||||
if err != nil {
|
||||
@ -241,54 +243,3 @@ func isServiceActive(name string) (bool, error) {
|
||||
}
|
||||
return initSystem.ServiceIsActive(name), nil
|
||||
}
|
||||
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
const cgroupDriverSystemd = "systemd"
|
||||
|
||||
// MutateCgroupDriver can be called to set the KubeletConfiguration cgroup driver to systemd.
|
||||
// Currently this cannot be as part of Default() because the function is called for
|
||||
// upgrades too, which can break existing nodes after a kubelet restart.
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
func MutateCgroupDriver(cfg *kubeadmapi.ClusterConfiguration) {
|
||||
cc, k, err := getKubeletConfig(cfg)
|
||||
if err != nil {
|
||||
klog.Warningf(err.Error())
|
||||
return
|
||||
}
|
||||
if len(k.CgroupDriver) == 0 {
|
||||
klog.V(1).Infof("setting the KubeletConfiguration cgroupDriver to %q", cgroupDriverSystemd)
|
||||
k.CgroupDriver = cgroupDriverSystemd
|
||||
cc.Set(k)
|
||||
}
|
||||
}
|
||||
|
||||
// WarnCgroupDriver prints a warning in case the user is not explicit
|
||||
// about the cgroupDriver value in the KubeletConfiguration.
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
func WarnCgroupDriver(cfg *kubeadmapi.ClusterConfiguration) {
|
||||
_, k, err := getKubeletConfig(cfg)
|
||||
if err != nil {
|
||||
klog.Warningf(err.Error())
|
||||
return
|
||||
}
|
||||
if len(k.CgroupDriver) == 0 {
|
||||
klog.Warningf("The 'cgroupDriver' value in the KubeletConfiguration is empty. " +
|
||||
"Starting from 1.22, 'kubeadm upgrade' will default an empty value to the 'systemd' cgroup driver. " +
|
||||
"The cgroup driver between the container runtime and the kubelet must match! " +
|
||||
"To learn more about this see: https://kubernetes.io/docs/setup/production-environment/container-runtimes/")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2376
|
||||
func getKubeletConfig(cfg *kubeadmapi.ClusterConfiguration) (kubeadmapi.ComponentConfig, *kubeletconfig.KubeletConfiguration, error) {
|
||||
errStr := fmt.Sprintf("setting the KubeletConfiguration cgroupDriver to %q failed unexpectedly", cgroupDriverSystemd)
|
||||
cc, ok := cfg.ComponentConfigs[KubeletGroup]
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("%s: %s", errStr, "missing kubelet component config")
|
||||
}
|
||||
k, ok := cc.Get().(*kubeletconfig.KubeletConfiguration)
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("%s: %s", errStr, "incompatible KubeletConfiguration")
|
||||
}
|
||||
return cc, k, nil
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -120,6 +121,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -158,6 +160,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -196,6 +199,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -230,6 +234,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -261,6 +266,7 @@ func TestKubeletDefault(t *testing.T) {
|
||||
HealthzPort: utilpointer.Int32Ptr(constants.KubeletHealthzPort),
|
||||
RotateCertificates: kubeletRotateCertificates,
|
||||
ResolverConfig: resolverConfig,
|
||||
CgroupDriver: constants.CgroupDriverSystemd,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -398,6 +398,11 @@ const (
|
||||
|
||||
// PauseVersion indicates the default pause image version for kubeadm
|
||||
PauseVersion = "3.4.1"
|
||||
|
||||
// CgroupDriverSystemd holds the systemd driver type
|
||||
CgroupDriverSystemd = "systemd"
|
||||
// CgroupDriverCgroupfs holds the cgroupfs driver type
|
||||
CgroupDriverCgroupfs = "cgroupfs"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -22,6 +22,7 @@ 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"
|
||||
)
|
||||
@ -32,12 +33,12 @@ func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
|
||||
if err != nil {
|
||||
return nil, []error{err}
|
||||
}
|
||||
if driver != kubeadmutil.CgroupDriverSystemd {
|
||||
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,
|
||||
kubeadmutil.CgroupDriverSystemd)
|
||||
constants.CgroupDriverSystemd)
|
||||
return []error{err}, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -24,13 +24,6 @@ import (
|
||||
utilsexec "k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
const (
|
||||
// CgroupDriverSystemd holds the systemd driver type
|
||||
CgroupDriverSystemd = "systemd"
|
||||
// CgroupDriverCgroupfs holds the cgroupfs driver type
|
||||
CgroupDriverCgroupfs = "cgroupfs"
|
||||
)
|
||||
|
||||
// TODO: add support for detecting the cgroup driver for CRI other than
|
||||
// Docker. Currently only Docker driver detection is supported:
|
||||
// Discussion:
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -50,7 +51,7 @@ func TestGetCgroupDriverDocker(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := tc.driver != CgroupDriverCgroupfs && tc.driver != CgroupDriverSystemd
|
||||
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