mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #126595 from pacoxu/kubelet-cgroup-v2-kernel-version
[1.32]kubelet: add log and event for cgroup v2 running on kernel < 5.8
This commit is contained in:
commit
24a74f887a
@ -46,7 +46,13 @@ import (
|
||||
|
||||
const (
|
||||
// Warning message for the users still using cgroup v1
|
||||
CgroupV1MaintenanceModeWarning = "Cgroup v1 support is in maintenance mode, please migrate to Cgroup v2."
|
||||
CgroupV1MaintenanceModeWarning = "cgroup v1 support is in maintenance mode, please migrate to cgroup v2"
|
||||
|
||||
// Warning message for the users using cgroup v2 on kernel doesn't support root `cpu.stat`.
|
||||
// `cpu.stat` was added to root cgroup in kernel 5.8.
|
||||
// (ref: https://github.com/torvalds/linux/commit/936f2a70f2077f64fab1dcb3eca71879e82ecd3f)
|
||||
CgroupV2KernelWarning = "cgroup v2 is being used on a kernel, which doesn't support root `cpu.stat`." +
|
||||
"Kubelet will continue, but may experience instability or wrong behavior"
|
||||
)
|
||||
|
||||
type ActivePodsFunc func() []*v1.Pod
|
||||
|
@ -1645,7 +1645,9 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
kl.warnCgroupV1Usage()
|
||||
if err := kl.cgroupVersionCheck(); err != nil {
|
||||
klog.V(2).InfoS("Warning: cgroup check", "error", err)
|
||||
}
|
||||
|
||||
// Start volume manager
|
||||
go kl.volumeManager.Run(ctx, kl.sourcesReady)
|
||||
@ -3067,12 +3069,3 @@ func (kl *Kubelet) PrepareDynamicResources(ctx context.Context, pod *v1.Pod) err
|
||||
func (kl *Kubelet) UnprepareDynamicResources(ctx context.Context, pod *v1.Pod) error {
|
||||
return kl.containerManager.UnprepareDynamicResources(ctx, pod)
|
||||
}
|
||||
|
||||
func (kl *Kubelet) warnCgroupV1Usage() {
|
||||
cgroupVersion := kl.containerManager.GetNodeConfig().CgroupVersion
|
||||
if cgroupVersion == 1 {
|
||||
kl.recorder.Eventf(kl.nodeRef, v1.EventTypeWarning, events.CgroupV1, cm.CgroupV1MaintenanceModeWarning)
|
||||
klog.V(2).InfoS("Warning: cgroup v1", "message", cm.CgroupV1MaintenanceModeWarning)
|
||||
}
|
||||
metrics.CgroupVersion.Set(float64(cgroupVersion))
|
||||
}
|
||||
|
51
pkg/kubelet/kubelet_linux.go
Normal file
51
pkg/kubelet/kubelet_linux.go
Normal file
@ -0,0 +1,51 @@
|
||||
//go:build linux
|
||||
|
||||
/*
|
||||
Copyright 2024 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 kubelet
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/util"
|
||||
"k8s.io/kubernetes/pkg/kubelet/events"
|
||||
"k8s.io/kubernetes/pkg/kubelet/metrics"
|
||||
)
|
||||
|
||||
func (kl *Kubelet) cgroupVersionCheck() error {
|
||||
cgroupVersion := kl.containerManager.GetNodeConfig().CgroupVersion
|
||||
metrics.CgroupVersion.Set(float64(cgroupVersion))
|
||||
switch cgroupVersion {
|
||||
case 1:
|
||||
kl.recorder.Eventf(kl.nodeRef, v1.EventTypeWarning, events.CgroupV1, cm.CgroupV1MaintenanceModeWarning)
|
||||
return errors.New(cm.CgroupV1MaintenanceModeWarning)
|
||||
case 2:
|
||||
cpustat := filepath.Join(util.CgroupRoot, "cpu.stat")
|
||||
if _, err := os.Stat(cpustat); os.IsNotExist(err) {
|
||||
// if `/sys/fs/cgroup/cpu.stat` does not exist, log a warning
|
||||
return errors.New(cm.CgroupV2KernelWarning)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported cgroup version: %d", cgroupVersion)
|
||||
}
|
||||
return nil
|
||||
}
|
25
pkg/kubelet/kubelet_others.go
Normal file
25
pkg/kubelet/kubelet_others.go
Normal file
@ -0,0 +1,25 @@
|
||||
//go:build !linux
|
||||
|
||||
/*
|
||||
Copyright 2024 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 kubelet
|
||||
|
||||
// cgroupVersionCheck performs a version check for the cgroup.
|
||||
// This method is not applicable for non-Linux operating systems.
|
||||
func (kl *Kubelet) cgroupVersionCheck() error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user