Add a warning log, event and metric for cgroup version 1
Signed-off-by: Harshal Patil <harpatil@redhat.com>
This commit is contained in:
		@@ -41,6 +41,10 @@ func NewCgroupManager(_ interface{}) CgroupManager {
 | 
				
			|||||||
	return &unsupportedCgroupManager{}
 | 
						return &unsupportedCgroupManager{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *unsupportedCgroupManager) Version() int {
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *unsupportedCgroupManager) Name(_ CgroupName) string {
 | 
					func (m *unsupportedCgroupManager) Name(_ CgroupName) string {
 | 
				
			||||||
	return ""
 | 
						return ""
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,6 +48,11 @@ func NewCgroupV1Manager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Version of the cgroup implementation on the host
 | 
				
			||||||
 | 
					func (c *cgroupV1impl) Version() int {
 | 
				
			||||||
 | 
						return 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate checks if all subsystem cgroups are valid
 | 
					// Validate checks if all subsystem cgroups are valid
 | 
				
			||||||
func (c *cgroupV1impl) Validate(name CgroupName) error {
 | 
					func (c *cgroupV1impl) Validate(name CgroupName) error {
 | 
				
			||||||
	// Get map of all cgroup paths on the system for the particular cgroup
 | 
						// Get map of all cgroup paths on the system for the particular cgroup
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,6 +47,11 @@ func NewCgroupV2Manager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Version of the cgroup implementation on the host
 | 
				
			||||||
 | 
					func (c *cgroupV2impl) Version() int {
 | 
				
			||||||
 | 
						return 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate checks if all subsystem cgroups are valid
 | 
					// Validate checks if all subsystem cgroups are valid
 | 
				
			||||||
func (c *cgroupV2impl) Validate(name CgroupName) error {
 | 
					func (c *cgroupV2impl) Validate(name CgroupName) error {
 | 
				
			||||||
	cgroupPath := c.buildCgroupUnifiedPath(name)
 | 
						cgroupPath := c.buildCgroupUnifiedPath(name)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,11 @@ import (
 | 
				
			|||||||
	"k8s.io/utils/cpuset"
 | 
						"k8s.io/utils/cpuset"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// Warning message for the users still using cgroup v1
 | 
				
			||||||
 | 
						CgroupV1MaintenanceModeWarning = "Cgroup v1 support is in maintenance mode, please migrate to Cgroup v2."
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ActivePodsFunc func() []*v1.Pod
 | 
					type ActivePodsFunc func() []*v1.Pod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Manages the containers running on a machine.
 | 
					// Manages the containers running on a machine.
 | 
				
			||||||
@@ -159,6 +164,7 @@ type NodeConfig struct {
 | 
				
			|||||||
	CPUCFSQuotaPeriod                       time.Duration
 | 
						CPUCFSQuotaPeriod                       time.Duration
 | 
				
			||||||
	TopologyManagerPolicy                   string
 | 
						TopologyManagerPolicy                   string
 | 
				
			||||||
	TopologyManagerPolicyOptions            map[string]string
 | 
						TopologyManagerPolicyOptions            map[string]string
 | 
				
			||||||
 | 
						CgroupVersion                           int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NodeAllocatableConfig struct {
 | 
					type NodeAllocatableConfig struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -245,6 +245,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
 | 
				
			|||||||
	// Turn CgroupRoot from a string (in cgroupfs path format) to internal CgroupName
 | 
						// Turn CgroupRoot from a string (in cgroupfs path format) to internal CgroupName
 | 
				
			||||||
	cgroupRoot := ParseCgroupfsToCgroupName(nodeConfig.CgroupRoot)
 | 
						cgroupRoot := ParseCgroupfsToCgroupName(nodeConfig.CgroupRoot)
 | 
				
			||||||
	cgroupManager := NewCgroupManager(subsystems, nodeConfig.CgroupDriver)
 | 
						cgroupManager := NewCgroupManager(subsystems, nodeConfig.CgroupDriver)
 | 
				
			||||||
 | 
						nodeConfig.CgroupVersion = cgroupManager.Version()
 | 
				
			||||||
	// Check if Cgroup-root actually exists on the node
 | 
						// Check if Cgroup-root actually exists on the node
 | 
				
			||||||
	if nodeConfig.CgroupsPerQOS {
 | 
						if nodeConfig.CgroupsPerQOS {
 | 
				
			||||||
		// this does default to / when enabled, but this tests against regressions.
 | 
							// this does default to / when enabled, but this tests against regressions.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,6 +88,8 @@ type CgroupManager interface {
 | 
				
			|||||||
	GetCgroupConfig(name CgroupName, resource v1.ResourceName) (*ResourceConfig, error)
 | 
						GetCgroupConfig(name CgroupName, resource v1.ResourceName) (*ResourceConfig, error)
 | 
				
			||||||
	// Set resource config for the specified resource type on the cgroup
 | 
						// Set resource config for the specified resource type on the cgroup
 | 
				
			||||||
	SetCgroupConfig(name CgroupName, resource v1.ResourceName, resourceConfig *ResourceConfig) error
 | 
						SetCgroupConfig(name CgroupName, resource v1.ResourceName, resourceConfig *ResourceConfig) error
 | 
				
			||||||
 | 
						// Version of the cgroup implementation on the host
 | 
				
			||||||
 | 
						Version() int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// QOSContainersInfo stores the names of containers per qos
 | 
					// QOSContainersInfo stores the names of containers per qos
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,6 +76,7 @@ const (
 | 
				
			|||||||
	FailedMountOnFilesystemMismatch      = "FailedMountOnFilesystemMismatch"
 | 
						FailedMountOnFilesystemMismatch      = "FailedMountOnFilesystemMismatch"
 | 
				
			||||||
	FailedPrepareDynamicResources        = "FailedPrepareDynamicResources"
 | 
						FailedPrepareDynamicResources        = "FailedPrepareDynamicResources"
 | 
				
			||||||
	PossibleMemoryBackedVolumesOnDisk    = "PossibleMemoryBackedVolumesOnDisk"
 | 
						PossibleMemoryBackedVolumesOnDisk    = "PossibleMemoryBackedVolumesOnDisk"
 | 
				
			||||||
 | 
						CgroupV1                             = "CgroupV1"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Image manager event reason list
 | 
					// Image manager event reason list
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1636,6 +1636,8 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) {
 | 
				
			|||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kl.warnCgroupV1Usage()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Start volume manager
 | 
						// Start volume manager
 | 
				
			||||||
	go kl.volumeManager.Run(kl.sourcesReady, wait.NeverStop)
 | 
						go kl.volumeManager.Run(kl.sourcesReady, wait.NeverStop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3021,3 +3023,12 @@ func (kl *Kubelet) PrepareDynamicResources(pod *v1.Pod) error {
 | 
				
			|||||||
func (kl *Kubelet) UnprepareDynamicResources(pod *v1.Pod) error {
 | 
					func (kl *Kubelet) UnprepareDynamicResources(pod *v1.Pod) error {
 | 
				
			||||||
	return kl.containerManager.UnprepareDynamicResources(pod)
 | 
						return kl.containerManager.UnprepareDynamicResources(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))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,6 +72,7 @@ const (
 | 
				
			|||||||
	OrphanedRuntimePodTotalKey         = "orphaned_runtime_pods_total"
 | 
						OrphanedRuntimePodTotalKey         = "orphaned_runtime_pods_total"
 | 
				
			||||||
	RestartedPodTotalKey               = "restarted_pods_total"
 | 
						RestartedPodTotalKey               = "restarted_pods_total"
 | 
				
			||||||
	ImagePullDurationKey               = "image_pull_duration_seconds"
 | 
						ImagePullDurationKey               = "image_pull_duration_seconds"
 | 
				
			||||||
 | 
						CgroupVersionKey                   = "cgroup_version"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Metrics keys of remote runtime operations
 | 
						// Metrics keys of remote runtime operations
 | 
				
			||||||
	RuntimeOperationsKey         = "runtime_operations_total"
 | 
						RuntimeOperationsKey         = "runtime_operations_total"
 | 
				
			||||||
@@ -907,6 +908,15 @@ var (
 | 
				
			|||||||
			StabilityLevel: metrics.ALPHA,
 | 
								StabilityLevel: metrics.ALPHA,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						CgroupVersion = metrics.NewGauge(
 | 
				
			||||||
 | 
							&metrics.GaugeOpts{
 | 
				
			||||||
 | 
								Subsystem:      KubeletSubsystem,
 | 
				
			||||||
 | 
								Name:           CgroupVersionKey,
 | 
				
			||||||
 | 
								Help:           "cgroup version on the hosts.",
 | 
				
			||||||
 | 
								StabilityLevel: metrics.ALPHA,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var registerMetrics sync.Once
 | 
					var registerMetrics sync.Once
 | 
				
			||||||
@@ -996,6 +1006,7 @@ func Register(collectors ...metrics.StableCollector) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		legacyregistry.MustRegister(LifecycleHandlerHTTPFallbacks)
 | 
							legacyregistry.MustRegister(LifecycleHandlerHTTPFallbacks)
 | 
				
			||||||
		legacyregistry.MustRegister(LifecycleHandlerSleepTerminated)
 | 
							legacyregistry.MustRegister(LifecycleHandlerSleepTerminated)
 | 
				
			||||||
 | 
							legacyregistry.MustRegister(CgroupVersion)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user