@@ -24,12 +24,14 @@ import (
24
24
"k8s.io/klog"
25
25
kubeletconfig "k8s.io/kubelet/config/v1beta1"
26
26
"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"
27
+ utilsexec "k8s.io/utils/exec"
27
28
utilpointer "k8s.io/utils/pointer"
28
29
29
30
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
30
31
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
31
32
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
32
33
"k8s.io/kubernetes/cmd/kubeadm/app/features"
34
+ kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
33
35
)
34
36
35
37
const (
@@ -96,7 +98,7 @@ func (kc *kubeletConfig) Unmarshal(docmap kubeadmapi.DocumentMap) error {
96
98
return kubeletHandler .Unmarshal (docmap , & kc .config )
97
99
}
98
100
99
- func (kc * kubeletConfig ) Default (cfg * kubeadmapi.ClusterConfiguration , _ * kubeadmapi.APIEndpoint ) {
101
+ func (kc * kubeletConfig ) Default (cfg * kubeadmapi.ClusterConfiguration , _ * kubeadmapi.APIEndpoint , nodeRegOpts * kubeadmapi. NodeRegistrationOptions ) {
100
102
const kind = "KubeletConfiguration"
101
103
102
104
if kc .config .FeatureGates == nil {
@@ -179,6 +181,21 @@ func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubead
179
181
// There is no way to determine if the user has set this or not, given the field is a non-pointer.
180
182
kc .config .RotateCertificates = kubeletRotateCertificates
181
183
184
+ // TODO: Conditionally set CgroupDriver to either `systemd` or `cgroupfs` for CRI other than Docker
185
+ if nodeRegOpts .CRISocket == constants .DefaultDockerCRISocket {
186
+ driver , err := kubeadmutil .GetCgroupDriverDocker (utilsexec .New ())
187
+ if err != nil {
188
+ klog .Warningf ("cannot automatically set CgroupDriver when starting the Kubelet: %v" , err )
189
+ } else {
190
+ // if we can parse the right cgroup driver from docker info,
191
+ // we should always override CgroupDriver here no matter user specifies this value explicitly or not
192
+ if kc .config .CgroupDriver != "" && kc .config .CgroupDriver != driver {
193
+ klog .Warningf ("detected %q as the Docker cgroup driver, the provided value %q in %q will be overrided" , driver , kc .config .CgroupDriver , kind )
194
+ }
195
+ kc .config .CgroupDriver = driver
196
+ }
197
+ }
198
+
182
199
ok , err := isServiceActive ("systemd-resolved" )
183
200
if err != nil {
184
201
klog .Warningf ("cannot determine if systemd-resolved is active: %v" , err )
0 commit comments