Remove unnecessary summary api call.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-02-08 22:57:30 +00:00
parent 1e1b32bf01
commit 91cbf93b90
3 changed files with 16 additions and 33 deletions

View File

@ -232,12 +232,15 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
} }
activePods := podFunc() activePods := podFunc()
// make observations and get a function to derive pod usage stats relative to those observations. updateStats := true
observations, statsFunc, err := makeSignalObservations(m.summaryProvider, capacityProvider, activePods) summary, err := m.summaryProvider.Get(updateStats)
if err != nil { if err != nil {
glog.Errorf("eviction manager: unexpected err: %v", err) glog.Errorf("eviction manager: failed to get get summary stats: %v", err)
return nil return nil
} }
// make observations and get a function to derive pod usage stats relative to those observations.
observations, statsFunc := makeSignalObservations(summary, capacityProvider, activePods)
debugLogObservations("observations", observations) debugLogObservations("observations", observations)
// attempt to create a threshold notifier to improve eviction response time // attempt to create a threshold notifier to improve eviction response time
@ -314,7 +317,7 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
// evict pods if there is a resource usage violation from local volume temporary storage // evict pods if there is a resource usage violation from local volume temporary storage
// If eviction happens in localStorageEviction function, skip the rest of eviction action // If eviction happens in localStorageEviction function, skip the rest of eviction action
if utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) { if utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
if evictedPods := m.localStorageEviction(activePods); len(evictedPods) > 0 { if evictedPods := m.localStorageEviction(summary, activePods); len(evictedPods) > 0 {
return evictedPods return evictedPods
} }
} }
@ -454,15 +457,7 @@ func (m *managerImpl) reclaimNodeLevelResources(resourceToReclaim v1.ResourceNam
// localStorageEviction checks the EmptyDir volume usage for each pod and determine whether it exceeds the specified limit and needs // localStorageEviction checks the EmptyDir volume usage for each pod and determine whether it exceeds the specified limit and needs
// to be evicted. It also checks every container in the pod, if the container overlay usage exceeds the limit, the pod will be evicted too. // to be evicted. It also checks every container in the pod, if the container overlay usage exceeds the limit, the pod will be evicted too.
func (m *managerImpl) localStorageEviction(pods []*v1.Pod) []*v1.Pod { func (m *managerImpl) localStorageEviction(summary *statsapi.Summary, pods []*v1.Pod) []*v1.Pod {
// do not update node-level stats as local storage evictions do not utilize them.
forceStatsUpdate := false
summary, err := m.summaryProvider.Get(forceStatsUpdate)
if err != nil {
glog.Errorf("Could not get summary provider")
return nil
}
statsFunc := cachedStatsFunc(summary.Pods) statsFunc := cachedStatsFunc(summary.Pods)
evicted := []*v1.Pod{} evicted := []*v1.Pod{}
for _, pod := range pods { for _, pod := range pods {

View File

@ -30,7 +30,6 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1" statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api" evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
"k8s.io/kubernetes/pkg/kubelet/server/stats"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types" kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
schedulerutils "k8s.io/kubernetes/pkg/scheduler/util" schedulerutils "k8s.io/kubernetes/pkg/scheduler/util"
) )
@ -715,12 +714,7 @@ func (a byEvictionPriority) Less(i, j int) bool {
} }
// makeSignalObservations derives observations using the specified summary provider. // makeSignalObservations derives observations using the specified summary provider.
func makeSignalObservations(summaryProvider stats.SummaryProvider, capacityProvider CapacityProvider, pods []*v1.Pod) (signalObservations, statsFunc, error) { func makeSignalObservations(summary *statsapi.Summary, capacityProvider CapacityProvider, pods []*v1.Pod) (signalObservations, statsFunc) {
updateStats := true
summary, err := summaryProvider.Get(updateStats)
if err != nil {
return nil, nil, err
}
// build the function to work against for pod stats // build the function to work against for pod stats
statsFunc := cachedStatsFunc(summary.Pods) statsFunc := cachedStatsFunc(summary.Pods)
// build an evaluation context for current eviction signals // build an evaluation context for current eviction signals
@ -787,7 +781,7 @@ func makeSignalObservations(summaryProvider stats.SummaryProvider, capacityProvi
glog.Errorf("Could not find capacity information for resource %v", v1.ResourceMemory) glog.Errorf("Could not find capacity information for resource %v", v1.ResourceMemory)
} }
return result, statsFunc, nil return result, statsFunc
} }
// thresholdsMet returns the set of thresholds that were met independent of grace period // thresholdsMet returns the set of thresholds that were met independent of grace period

View File

@ -993,9 +993,6 @@ func TestMakeSignalObservations(t *testing.T) {
}, },
Pods: []statsapi.PodStats{}, Pods: []statsapi.PodStats{},
} }
provider := &fakeSummaryProvider{
result: fakeStats,
}
pods := []*v1.Pod{ pods := []*v1.Pod{
podMaker("pod1", "ns1", "uuid1", 1), podMaker("pod1", "ns1", "uuid1", 1),
podMaker("pod1", "ns2", "uuid2", 1), podMaker("pod1", "ns2", "uuid2", 1),
@ -1011,10 +1008,7 @@ func TestMakeSignalObservations(t *testing.T) {
if res.CmpInt64(int64(allocatableMemoryCapacity)) != 0 { if res.CmpInt64(int64(allocatableMemoryCapacity)) != 0 {
t.Errorf("Expected Threshold %v to be equal to value %v", res.Value(), allocatableMemoryCapacity) t.Errorf("Expected Threshold %v to be equal to value %v", res.Value(), allocatableMemoryCapacity)
} }
actualObservations, statsFunc, err := makeSignalObservations(provider, capacityProvider, pods) actualObservations, statsFunc := makeSignalObservations(fakeStats, capacityProvider, pods)
if err != nil {
t.Errorf("Unexpected err: %v", err)
}
allocatableMemQuantity, found := actualObservations[evictionapi.SignalAllocatableMemoryAvailable] allocatableMemQuantity, found := actualObservations[evictionapi.SignalAllocatableMemoryAvailable]
if !found { if !found {
t.Errorf("Expected allocatable memory observation, but didnt find one") t.Errorf("Expected allocatable memory observation, but didnt find one")
@ -1027,7 +1021,7 @@ func TestMakeSignalObservations(t *testing.T) {
} }
memQuantity, found := actualObservations[evictionapi.SignalMemoryAvailable] memQuantity, found := actualObservations[evictionapi.SignalMemoryAvailable]
if !found { if !found {
t.Errorf("Expected available memory observation: %v", err) t.Error("Expected available memory observation")
} }
if expectedBytes := int64(nodeAvailableBytes); memQuantity.available.Value() != expectedBytes { if expectedBytes := int64(nodeAvailableBytes); memQuantity.available.Value() != expectedBytes {
t.Errorf("Expected %v, actual: %v", expectedBytes, memQuantity.available.Value()) t.Errorf("Expected %v, actual: %v", expectedBytes, memQuantity.available.Value())
@ -1037,7 +1031,7 @@ func TestMakeSignalObservations(t *testing.T) {
} }
nodeFsQuantity, found := actualObservations[evictionapi.SignalNodeFsAvailable] nodeFsQuantity, found := actualObservations[evictionapi.SignalNodeFsAvailable]
if !found { if !found {
t.Errorf("Expected available nodefs observation: %v", err) t.Error("Expected available nodefs observation")
} }
if expectedBytes := int64(nodeFsAvailableBytes); nodeFsQuantity.available.Value() != expectedBytes { if expectedBytes := int64(nodeFsAvailableBytes); nodeFsQuantity.available.Value() != expectedBytes {
t.Errorf("Expected %v, actual: %v", expectedBytes, nodeFsQuantity.available.Value()) t.Errorf("Expected %v, actual: %v", expectedBytes, nodeFsQuantity.available.Value())
@ -1047,7 +1041,7 @@ func TestMakeSignalObservations(t *testing.T) {
} }
nodeFsInodesQuantity, found := actualObservations[evictionapi.SignalNodeFsInodesFree] nodeFsInodesQuantity, found := actualObservations[evictionapi.SignalNodeFsInodesFree]
if !found { if !found {
t.Errorf("Expected inodes free nodefs observation: %v", err) t.Error("Expected inodes free nodefs observation")
} }
if expected := int64(nodeFsInodesFree); nodeFsInodesQuantity.available.Value() != expected { if expected := int64(nodeFsInodesFree); nodeFsInodesQuantity.available.Value() != expected {
t.Errorf("Expected %v, actual: %v", expected, nodeFsInodesQuantity.available.Value()) t.Errorf("Expected %v, actual: %v", expected, nodeFsInodesQuantity.available.Value())
@ -1057,7 +1051,7 @@ func TestMakeSignalObservations(t *testing.T) {
} }
imageFsQuantity, found := actualObservations[evictionapi.SignalImageFsAvailable] imageFsQuantity, found := actualObservations[evictionapi.SignalImageFsAvailable]
if !found { if !found {
t.Errorf("Expected available imagefs observation: %v", err) t.Error("Expected available imagefs observation")
} }
if expectedBytes := int64(imageFsAvailableBytes); imageFsQuantity.available.Value() != expectedBytes { if expectedBytes := int64(imageFsAvailableBytes); imageFsQuantity.available.Value() != expectedBytes {
t.Errorf("Expected %v, actual: %v", expectedBytes, imageFsQuantity.available.Value()) t.Errorf("Expected %v, actual: %v", expectedBytes, imageFsQuantity.available.Value())
@ -1067,7 +1061,7 @@ func TestMakeSignalObservations(t *testing.T) {
} }
imageFsInodesQuantity, found := actualObservations[evictionapi.SignalImageFsInodesFree] imageFsInodesQuantity, found := actualObservations[evictionapi.SignalImageFsInodesFree]
if !found { if !found {
t.Errorf("Expected inodes free imagefs observation: %v", err) t.Error("Expected inodes free imagefs observation")
} }
if expected := int64(imageFsInodesFree); imageFsInodesQuantity.available.Value() != expected { if expected := int64(imageFsInodesFree); imageFsInodesQuantity.available.Value() != expected {
t.Errorf("Expected %v, actual: %v", expected, imageFsInodesQuantity.available.Value()) t.Errorf("Expected %v, actual: %v", expected, imageFsInodesQuantity.available.Value())