From a072bda6fd598f2afdb5b30f571ae37e4700d70e Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Wed, 24 Aug 2016 18:39:46 -0700 Subject: [PATCH] Print out resource name when evicting pods --- pkg/kubelet/eviction/eviction_manager.go | 11 ++++++++--- pkg/kubelet/eviction/helpers.go | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/eviction/eviction_manager.go b/pkg/kubelet/eviction/eviction_manager.go index 8395b3c4fa..4e3ff2f741 100644 --- a/pkg/kubelet/eviction/eviction_manager.go +++ b/pkg/kubelet/eviction/eviction_manager.go @@ -98,8 +98,12 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd return lifecycle.PodAdmitResult{Admit: true} } - // the node has memory pressure, admit if not best-effort + // Check the node conditions to identify the resource under pressure. + // The resource can only be either disk or memory; set the default to disk. + resource := api.ResourceStorage if hasNodeCondition(m.nodeConditions, api.NodeMemoryPressure) { + resource = api.ResourceMemory + // the node has memory pressure, admit if not best-effort notBestEffort := qos.BestEffort != qos.GetPodQOS(attrs.Pod) if notBestEffort { return lifecycle.PodAdmitResult{Admit: true} @@ -107,11 +111,11 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd } // reject pods when under memory pressure (if pod is best effort), or if under disk pressure. - glog.Warningf("Failed to admit pod %v - %s", format.Pod(attrs.Pod), "node has conditions: %v", m.nodeConditions) + glog.Warningf("Failed to admit pod %q - node has conditions: %v", format.Pod(attrs.Pod), m.nodeConditions) return lifecycle.PodAdmitResult{ Admit: false, Reason: reason, - Message: message, + Message: getMessage(resource), } } @@ -244,6 +248,7 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act glog.Infof("eviction manager: pods ranked for eviction: %s", format.Pods(activePods)) // we kill at most a single pod during each eviction interval + message := getMessage(resourceToReclaim) for i := range activePods { pod := activePods[i] status := api.PodStatus{ diff --git a/pkg/kubelet/eviction/helpers.go b/pkg/kubelet/eviction/helpers.go index 8221c48972..81f040eec9 100644 --- a/pkg/kubelet/eviction/helpers.go +++ b/pkg/kubelet/eviction/helpers.go @@ -37,8 +37,8 @@ const ( unsupportedEvictionSignal = "unsupported eviction signal %v" // the reason reported back in status. reason = "Evicted" - // the message associated with the reason. - message = "The node was low on compute resources." + // the message format associated with the reason. + messageFmt = "The node was low on %s." // disk, in bytes. internal to this module, used to account for local disk usage. resourceDisk api.ResourceName = "disk" // inodes, number. internal to this module, used to account for local disk inode consumption. @@ -888,3 +888,7 @@ func deleteImages(imageGC ImageGC, reportBytesFreed bool) nodeReclaimFunc { return resource.NewQuantity(reclaimed, resource.BinarySI), nil } } + +func getMessage(resource api.ResourceName) string { + return fmt.Sprintf(messageFmt, resource) +}