mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
fix eviction event formatting
This commit is contained in:
parent
93b6d026d9
commit
b7deb6d9e0
@ -157,7 +157,7 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
|
|||||||
return lifecycle.PodAdmitResult{
|
return lifecycle.PodAdmitResult{
|
||||||
Admit: false,
|
Admit: false,
|
||||||
Reason: Reason,
|
Reason: Reason,
|
||||||
Message: fmt.Sprintf(message, m.nodeConditions),
|
Message: fmt.Sprintf(nodeLowMessageFmt, m.nodeConditions),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ func (m *managerImpl) emptyDirLimitEviction(podStats statsapi.PodStats, pod *v1.
|
|||||||
used := podVolumeUsed[pod.Spec.Volumes[i].Name]
|
used := podVolumeUsed[pod.Spec.Volumes[i].Name]
|
||||||
if used != nil && size != nil && size.Sign() == 1 && used.Cmp(*size) > 0 {
|
if used != nil && size != nil && size.Sign() == 1 && used.Cmp(*size) > 0 {
|
||||||
// the emptyDir usage exceeds the size limit, evict the pod
|
// the emptyDir usage exceeds the size limit, evict the pod
|
||||||
return m.evictPod(pod, 0, fmt.Sprintf(emptyDirMessage, pod.Spec.Volumes[i].Name, size.String()), nil)
|
return m.evictPod(pod, 0, fmt.Sprintf(emptyDirMessageFmt, pod.Spec.Volumes[i].Name, size.String()), nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,7 +510,7 @@ func (m *managerImpl) podEphemeralStorageLimitEviction(podStats statsapi.PodStat
|
|||||||
podEphemeralStorageLimit := podLimits[v1.ResourceEphemeralStorage]
|
podEphemeralStorageLimit := podLimits[v1.ResourceEphemeralStorage]
|
||||||
if podEphemeralStorageTotalUsage.Cmp(podEphemeralStorageLimit) > 0 {
|
if podEphemeralStorageTotalUsage.Cmp(podEphemeralStorageLimit) > 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, 0, fmt.Sprintf(podEphemeralStorageMessage, podEphemeralStorageLimit.String()), nil)
|
return m.evictPod(pod, 0, fmt.Sprintf(podEphemeralStorageMessageFmt, podEphemeralStorageLimit.String()), nil)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -532,7 +532,7 @@ func (m *managerImpl) containerEphemeralStorageLimitEviction(podStats statsapi.P
|
|||||||
|
|
||||||
if ephemeralStorageThreshold, ok := thresholdsMap[containerStat.Name]; ok {
|
if ephemeralStorageThreshold, ok := thresholdsMap[containerStat.Name]; ok {
|
||||||
if ephemeralStorageThreshold.Cmp(*containerUsed) < 0 {
|
if ephemeralStorageThreshold.Cmp(*containerUsed) < 0 {
|
||||||
return m.evictPod(pod, 0, fmt.Sprintf(containerEphemeralStorageMessage, containerStat.Name, ephemeralStorageThreshold.String()), nil)
|
return m.evictPod(pod, 0, fmt.Sprintf(containerEphemeralStorageMessageFmt, containerStat.Name, ephemeralStorageThreshold.String()), nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,16 +38,16 @@ const (
|
|||||||
unsupportedEvictionSignal = "unsupported eviction signal %v"
|
unsupportedEvictionSignal = "unsupported eviction signal %v"
|
||||||
// Reason is the reason reported back in status.
|
// Reason is the reason reported back in status.
|
||||||
Reason = "Evicted"
|
Reason = "Evicted"
|
||||||
// the message associated with the reason.
|
// nodeLowMessageFmt is the message for evictions due to resource pressure.
|
||||||
message = "The node was low on resource: %v. "
|
nodeLowMessageFmt = "The node was low on resource: %v. "
|
||||||
// additional information for containers exceeding requests
|
// containerMessageFmt provides additional information for containers exceeding requests
|
||||||
containerMessage = "Container %s was using %s, which exceeds its request of %s. "
|
containerMessageFmt = "Container %s was using %s, which exceeds its request of %s. "
|
||||||
// additional information for containers which have exceeded their ES limit
|
// containerEphemeralStorageMessageFmt provides additional information for containers which have exceeded their ES limit
|
||||||
containerEphemeralStorageMessage = "Container %s exceeded its local ephemeral storage limit %q. "
|
containerEphemeralStorageMessageFmt = "Container %s exceeded its local ephemeral storage limit %q. "
|
||||||
// additional information for pods which have exceeded their ES limit
|
// podEphemeralStorageMessageFmt provides additional information for pods which have exceeded their ES limit
|
||||||
podEphemeralStorageMessage = "Pod ephemeral local storage usage exceeds the total limit of containers %s. "
|
podEphemeralStorageMessageFmt = "Pod ephemeral local storage usage exceeds the total limit of containers %s. "
|
||||||
// additional information for empty-dir volumes which have exceeded their size limit
|
// emptyDirMessageFmt provides additional information for empty-dir volumes which have exceeded their size limit
|
||||||
emptyDirMessage = "Usage of EmptyDir volume %q exceeds the limit %q. "
|
emptyDirMessageFmt = "Usage of EmptyDir volume %q exceeds the limit %q. "
|
||||||
// inodes, number. internal to this module, used to account for local disk inode consumption.
|
// inodes, number. internal to this module, used to account for local disk inode consumption.
|
||||||
resourceInodes v1.ResourceName = "inodes"
|
resourceInodes v1.ResourceName = "inodes"
|
||||||
// OffendingContainersKey is the key in eviction event annotations for the list of container names which exceeded their requests
|
// OffendingContainersKey is the key in eviction event annotations for the list of container names which exceeded their requests
|
||||||
@ -1061,7 +1061,7 @@ func buildSignalToNodeReclaimFuncs(imageGC ImageGC, containerGC ContainerGC, wit
|
|||||||
// evictionMessage constructs a useful message about why an eviction occurred, and annotations to provide metadata about the eviction
|
// evictionMessage constructs a useful message about why an eviction occurred, and annotations to provide metadata about the eviction
|
||||||
func evictionMessage(resourceToReclaim v1.ResourceName, pod *v1.Pod, stats statsFunc) (message string, annotations map[string]string) {
|
func evictionMessage(resourceToReclaim v1.ResourceName, pod *v1.Pod, stats statsFunc) (message string, annotations map[string]string) {
|
||||||
annotations = make(map[string]string)
|
annotations = make(map[string]string)
|
||||||
message = fmt.Sprintf(message, resourceToReclaim)
|
message = fmt.Sprintf(nodeLowMessageFmt, resourceToReclaim)
|
||||||
containers := []string{}
|
containers := []string{}
|
||||||
containerUsage := []string{}
|
containerUsage := []string{}
|
||||||
podStats, ok := stats(pod)
|
podStats, ok := stats(pod)
|
||||||
@ -1084,7 +1084,7 @@ func evictionMessage(resourceToReclaim v1.ResourceName, pod *v1.Pod, stats stats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if usage != nil && usage.Cmp(requests) > 0 {
|
if usage != nil && usage.Cmp(requests) > 0 {
|
||||||
message += fmt.Sprintf(containerMessage, container.Name, usage.String(), requests.String())
|
message += fmt.Sprintf(containerMessageFmt, container.Name, usage.String(), requests.String())
|
||||||
containers = append(containers, container.Name)
|
containers = append(containers, container.Name)
|
||||||
containerUsage = append(containerUsage, usage.String())
|
containerUsage = append(containerUsage, usage.String())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user