mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Fix pod local ephemeral storage usage
This commit is contained in:
parent
4ba2b625c5
commit
9fadd3bd9a
@ -520,13 +520,13 @@ func (m *managerImpl) podEphemeralStorageLimitEviction(podStats statsapi.PodStat
|
|||||||
} else {
|
} else {
|
||||||
fsStatsSet = []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}
|
fsStatsSet = []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}
|
||||||
}
|
}
|
||||||
podUsage, err := podDiskUsage(podStats, pod, fsStatsSet)
|
podEphemeralUsage, err := podLocalEphemeralStorageUsage(podStats, pod, fsStatsSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("eviction manager: error getting pod disk usage %v", err)
|
glog.Errorf("eviction manager: error getting pod disk usage %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
podEphemeralStorageTotalUsage.Add(podUsage[resourceDisk])
|
podEphemeralStorageTotalUsage.Add(podEphemeralUsage[resourceDisk])
|
||||||
if podEphemeralStorageTotalUsage.Cmp(podLimits[v1.ResourceEphemeralStorage]) > 0 {
|
if podEphemeralStorageTotalUsage.Cmp(podLimits[v1.ResourceEphemeralStorage]) > 0 {
|
||||||
// the total usage of pod exceeds the total size limit of containers, evict the pod
|
// the total usage of pod exceeds the total size limit of containers, evict the pod
|
||||||
return m.evictPod(pod, v1.ResourceEphemeralStorage, fmt.Sprintf("pod ephemeral local storage usage exceeds the total limit of containers %v", podLimits[v1.ResourceEphemeralStorage]))
|
return m.evictPod(pod, v1.ResourceEphemeralStorage, fmt.Sprintf("pod ephemeral local storage usage exceeds the total limit of containers %v", podLimits[v1.ResourceEphemeralStorage]))
|
||||||
|
@ -394,8 +394,8 @@ func localVolumeNames(pod *v1.Pod) []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// podDiskUsage aggregates pod disk usage and inode consumption for the specified stats to measure.
|
// containerUsage aggregates container disk usage and inode consumption for the specified stats to measure.
|
||||||
func podDiskUsage(podStats statsapi.PodStats, pod *v1.Pod, statsToMeasure []fsStatsType) (v1.ResourceList, error) {
|
func containerUsage(podStats statsapi.PodStats, statsToMeasure []fsStatsType) v1.ResourceList {
|
||||||
disk := resource.Quantity{Format: resource.BinarySI}
|
disk := resource.Quantity{Format: resource.BinarySI}
|
||||||
inodes := resource.Quantity{Format: resource.BinarySI}
|
inodes := resource.Quantity{Format: resource.BinarySI}
|
||||||
for _, container := range podStats.Containers {
|
for _, container := range podStats.Containers {
|
||||||
@ -408,18 +408,46 @@ func podDiskUsage(podStats statsapi.PodStats, pod *v1.Pod, statsToMeasure []fsSt
|
|||||||
inodes.Add(*inodeUsage(container.Logs))
|
inodes.Add(*inodeUsage(container.Logs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasFsStatsType(statsToMeasure, fsStatsLocalVolumeSource) {
|
return v1.ResourceList{
|
||||||
volumeNames := localVolumeNames(pod)
|
resourceDisk: disk,
|
||||||
for _, volumeName := range volumeNames {
|
resourceInodes: inodes,
|
||||||
for _, volumeStats := range podStats.VolumeStats {
|
}
|
||||||
if volumeStats.Name == volumeName {
|
}
|
||||||
disk.Add(*diskUsage(&volumeStats.FsStats))
|
|
||||||
inodes.Add(*inodeUsage(&volumeStats.FsStats))
|
// podLocalVolumeUsage aggregates pod local volumes disk usage and inode consumption for the specified stats to measure.
|
||||||
break
|
func podLocalVolumeUsage(volumeNames []string, podStats statsapi.PodStats) v1.ResourceList {
|
||||||
}
|
disk := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
inodes := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
for _, volumeName := range volumeNames {
|
||||||
|
for _, volumeStats := range podStats.VolumeStats {
|
||||||
|
if volumeStats.Name == volumeName {
|
||||||
|
disk.Add(*diskUsage(&volumeStats.FsStats))
|
||||||
|
inodes.Add(*inodeUsage(&volumeStats.FsStats))
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return v1.ResourceList{
|
||||||
|
resourceDisk: disk,
|
||||||
|
resourceInodes: inodes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// podDiskUsage aggregates pod disk usage and inode consumption for the specified stats to measure.
|
||||||
|
func podDiskUsage(podStats statsapi.PodStats, pod *v1.Pod, statsToMeasure []fsStatsType) (v1.ResourceList, error) {
|
||||||
|
disk := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
inodes := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
|
||||||
|
containerUsageList := containerUsage(podStats, statsToMeasure)
|
||||||
|
disk.Add(containerUsageList[resourceDisk])
|
||||||
|
inodes.Add(containerUsageList[resourceInodes])
|
||||||
|
|
||||||
|
if hasFsStatsType(statsToMeasure, fsStatsLocalVolumeSource) {
|
||||||
|
volumeNames := localVolumeNames(pod)
|
||||||
|
podLocalVolumeUsageList := podLocalVolumeUsage(volumeNames, podStats)
|
||||||
|
disk.Add(podLocalVolumeUsageList[resourceDisk])
|
||||||
|
inodes.Add(podLocalVolumeUsageList[resourceInodes])
|
||||||
|
}
|
||||||
return v1.ResourceList{
|
return v1.ResourceList{
|
||||||
resourceDisk: disk,
|
resourceDisk: disk,
|
||||||
resourceInodes: inodes,
|
resourceInodes: inodes,
|
||||||
@ -444,6 +472,40 @@ func podMemoryUsage(podStats statsapi.PodStats) (v1.ResourceList, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// localEphemeralVolumeNames returns the set of ephemeral volumes for the pod that are local
|
||||||
|
func localEphemeralVolumeNames(pod *v1.Pod) []string {
|
||||||
|
result := []string{}
|
||||||
|
for _, volume := range pod.Spec.Volumes {
|
||||||
|
if volume.GitRepo != nil ||
|
||||||
|
(volume.EmptyDir != nil && volume.EmptyDir.Medium != v1.StorageMediumMemory) ||
|
||||||
|
volume.ConfigMap != nil || volume.DownwardAPI != nil {
|
||||||
|
result = append(result, volume.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// podLocalEphemeralStorageUsage aggregates pod local ephemeral storage usage and inode consumption for the specified stats to measure.
|
||||||
|
func podLocalEphemeralStorageUsage(podStats statsapi.PodStats, pod *v1.Pod, statsToMeasure []fsStatsType) (v1.ResourceList, error) {
|
||||||
|
disk := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
inodes := resource.Quantity{Format: resource.BinarySI}
|
||||||
|
|
||||||
|
containerUsageList := containerUsage(podStats, statsToMeasure)
|
||||||
|
disk.Add(containerUsageList[resourceDisk])
|
||||||
|
inodes.Add(containerUsageList[resourceInodes])
|
||||||
|
|
||||||
|
if hasFsStatsType(statsToMeasure, fsStatsLocalVolumeSource) {
|
||||||
|
volumeNames := localEphemeralVolumeNames(pod)
|
||||||
|
podLocalVolumeUsageList := podLocalVolumeUsage(volumeNames, podStats)
|
||||||
|
disk.Add(podLocalVolumeUsageList[resourceDisk])
|
||||||
|
inodes.Add(podLocalVolumeUsageList[resourceInodes])
|
||||||
|
}
|
||||||
|
return v1.ResourceList{
|
||||||
|
resourceDisk: disk,
|
||||||
|
resourceInodes: inodes,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// formatThreshold formats a threshold for logging.
|
// formatThreshold formats a threshold for logging.
|
||||||
func formatThreshold(threshold evictionapi.Threshold) string {
|
func formatThreshold(threshold evictionapi.Threshold) string {
|
||||||
return fmt.Sprintf("threshold(signal=%v, operator=%v, value=%v, gracePeriod=%v)", threshold.Signal, threshold.Operator, evictionapi.ThresholdValue(threshold.Value), threshold.GracePeriod)
|
return fmt.Sprintf("threshold(signal=%v, operator=%v, value=%v, gracePeriod=%v)", threshold.Signal, threshold.Operator, evictionapi.ThresholdValue(threshold.Value), threshold.GracePeriod)
|
||||||
|
Loading…
Reference in New Issue
Block a user