Skip to content

Commit 5a99930

Browse files
authored
Merge pull request kubernetes#125328 from harche/v1_warning
[KEP-4569] Add a warning log, an event for cgroup v1 usage and a metric for cgroup version
2 parents 1740d85 + 68d317a commit 5a99930

File tree

9 files changed

+46
-0
lines changed

9 files changed

+46
-0
lines changed

pkg/kubelet/cm/cgroup_manager_unsupported.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func NewCgroupManager(_ interface{}) CgroupManager {
4141
return &unsupportedCgroupManager{}
4242
}
4343

44+
func (m *unsupportedCgroupManager) Version() int {
45+
return 0
46+
}
47+
4448
func (m *unsupportedCgroupManager) Name(_ CgroupName) string {
4549
return ""
4650
}

pkg/kubelet/cm/cgroup_v1_manager_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func NewCgroupV1Manager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager
4848
}
4949
}
5050

51+
// Version of the cgroup implementation on the host
52+
func (c *cgroupV1impl) Version() int {
53+
return 1
54+
}
55+
5156
// Validate checks if all subsystem cgroups are valid
5257
func (c *cgroupV1impl) Validate(name CgroupName) error {
5358
// Get map of all cgroup paths on the system for the particular cgroup

pkg/kubelet/cm/cgroup_v2_manager_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func NewCgroupV2Manager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager
4747
}
4848
}
4949

50+
// Version of the cgroup implementation on the host
51+
func (c *cgroupV2impl) Version() int {
52+
return 2
53+
}
54+
5055
// Validate checks if all subsystem cgroups are valid
5156
func (c *cgroupV2impl) Validate(name CgroupName) error {
5257
cgroupPath := c.buildCgroupUnifiedPath(name)

pkg/kubelet/cm/container_manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ import (
4242
"k8s.io/utils/cpuset"
4343
)
4444

45+
const (
46+
// Warning message for the users still using cgroup v1
47+
CgroupV1MaintenanceModeWarning = "Cgroup v1 support is in maintenance mode, please migrate to Cgroup v2."
48+
)
49+
4550
type ActivePodsFunc func() []*v1.Pod
4651

4752
// Manages the containers running on a machine.
@@ -159,6 +164,7 @@ type NodeConfig struct {
159164
CPUCFSQuotaPeriod time.Duration
160165
TopologyManagerPolicy string
161166
TopologyManagerPolicyOptions map[string]string
167+
CgroupVersion int
162168
}
163169

164170
type NodeAllocatableConfig struct {

pkg/kubelet/cm/container_manager_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
245245
// Turn CgroupRoot from a string (in cgroupfs path format) to internal CgroupName
246246
cgroupRoot := ParseCgroupfsToCgroupName(nodeConfig.CgroupRoot)
247247
cgroupManager := NewCgroupManager(subsystems, nodeConfig.CgroupDriver)
248+
nodeConfig.CgroupVersion = cgroupManager.Version()
248249
// Check if Cgroup-root actually exists on the node
249250
if nodeConfig.CgroupsPerQOS {
250251
// this does default to / when enabled, but this tests against regressions.

pkg/kubelet/cm/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type CgroupManager interface {
8888
GetCgroupConfig(name CgroupName, resource v1.ResourceName) (*ResourceConfig, error)
8989
// Set resource config for the specified resource type on the cgroup
9090
SetCgroupConfig(name CgroupName, resource v1.ResourceName, resourceConfig *ResourceConfig) error
91+
// Version of the cgroup implementation on the host
92+
Version() int
9193
}
9294

9395
// QOSContainersInfo stores the names of containers per qos

pkg/kubelet/events/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const (
7676
FailedMountOnFilesystemMismatch = "FailedMountOnFilesystemMismatch"
7777
FailedPrepareDynamicResources = "FailedPrepareDynamicResources"
7878
PossibleMemoryBackedVolumesOnDisk = "PossibleMemoryBackedVolumesOnDisk"
79+
CgroupV1 = "CgroupV1"
7980
)
8081

8182
// Image manager event reason list

pkg/kubelet/kubelet.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,8 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) {
16361636
os.Exit(1)
16371637
}
16381638

1639+
kl.warnCgroupV1Usage()
1640+
16391641
// Start volume manager
16401642
go kl.volumeManager.Run(kl.sourcesReady, wait.NeverStop)
16411643

@@ -3021,3 +3023,12 @@ func (kl *Kubelet) PrepareDynamicResources(pod *v1.Pod) error {
30213023
func (kl *Kubelet) UnprepareDynamicResources(pod *v1.Pod) error {
30223024
return kl.containerManager.UnprepareDynamicResources(pod)
30233025
}
3026+
3027+
func (kl *Kubelet) warnCgroupV1Usage() {
3028+
cgroupVersion := kl.containerManager.GetNodeConfig().CgroupVersion
3029+
if cgroupVersion == 1 {
3030+
kl.recorder.Eventf(kl.nodeRef, v1.EventTypeWarning, events.CgroupV1, cm.CgroupV1MaintenanceModeWarning)
3031+
klog.V(2).InfoS("Warning: cgroup v1", "message", cm.CgroupV1MaintenanceModeWarning)
3032+
}
3033+
metrics.CgroupVersion.Set(float64(cgroupVersion))
3034+
}

pkg/kubelet/metrics/metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
OrphanedRuntimePodTotalKey = "orphaned_runtime_pods_total"
7373
RestartedPodTotalKey = "restarted_pods_total"
7474
ImagePullDurationKey = "image_pull_duration_seconds"
75+
CgroupVersionKey = "cgroup_version"
7576

7677
// Metrics keys of remote runtime operations
7778
RuntimeOperationsKey = "runtime_operations_total"
@@ -907,6 +908,15 @@ var (
907908
StabilityLevel: metrics.ALPHA,
908909
},
909910
)
911+
912+
CgroupVersion = metrics.NewGauge(
913+
&metrics.GaugeOpts{
914+
Subsystem: KubeletSubsystem,
915+
Name: CgroupVersionKey,
916+
Help: "cgroup version on the hosts.",
917+
StabilityLevel: metrics.ALPHA,
918+
},
919+
)
910920
)
911921

912922
var registerMetrics sync.Once
@@ -996,6 +1006,7 @@ func Register(collectors ...metrics.StableCollector) {
9961006

9971007
legacyregistry.MustRegister(LifecycleHandlerHTTPFallbacks)
9981008
legacyregistry.MustRegister(LifecycleHandlerSleepTerminated)
1009+
legacyregistry.MustRegister(CgroupVersion)
9991010
})
10001011
}
10011012

0 commit comments

Comments
 (0)