From 0de1e62b304cc90b78b4a754612c918e68b7da4f Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Mon, 25 Jul 2016 22:40:22 -0400 Subject: [PATCH] modify fsStats to fsStatsType to avoid confusion with cadvisor types --- pkg/kubelet/eviction/helpers.go | 26 ++++++++++--------- pkg/kubelet/eviction/helpers_test.go | 4 +-- pkg/kubelet/eviction/types.go | 10 +++---- .../algorithm/predicates/predicates_test.go | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pkg/kubelet/eviction/helpers.go b/pkg/kubelet/eviction/helpers.go index d38d31c4410..ea6911240d2 100644 --- a/pkg/kubelet/eviction/helpers.go +++ b/pkg/kubelet/eviction/helpers.go @@ -255,6 +255,7 @@ func memoryUsage(memStats *statsapi.MemoryStats) *resource.Quantity { } // localVolumeNames returns the set of volumes for the pod that are local +// TODO: sumamry API should report what volumes consume local storage rather than hard-code here. func localVolumeNames(pod *api.Pod) []string { result := []string{} for _, volume := range pod.Spec.Volumes { @@ -269,22 +270,23 @@ func localVolumeNames(pod *api.Pod) []string { } // podDiskUsage aggregates pod disk usage for the specified stats to measure. -func podDiskUsage(podStats statsapi.PodStats, pod *api.Pod, statsToMeasure []fsStats) (api.ResourceList, error) { +func podDiskUsage(podStats statsapi.PodStats, pod *api.Pod, statsToMeasure []fsStatsType) (api.ResourceList, error) { disk := resource.Quantity{Format: resource.BinarySI} for _, container := range podStats.Containers { - if hasFsStats(statsToMeasure, fsStatsRoot) { + if hasFsStatsType(statsToMeasure, fsStatsRoot) { disk.Add(*diskUsage(container.Rootfs)) } - if hasFsStats(statsToMeasure, fsStatsLogs) { + if hasFsStatsType(statsToMeasure, fsStatsLogs) { disk.Add(*diskUsage(container.Logs)) } } - if hasFsStats(statsToMeasure, fsStatsLocalVolumeSource) { + if hasFsStatsType(statsToMeasure, fsStatsLocalVolumeSource) { volumeNames := localVolumeNames(pod) for _, volumeName := range volumeNames { for _, volumeStats := range podStats.VolumeStats { if volumeStats.Name == volumeName { disk.Add(*diskUsage(&volumeStats.FsStats)) + break } } } @@ -451,7 +453,7 @@ func memory(stats statsFunc) cmpFunc { } // disk compares pods by largest consumer of disk relative to request. -func disk(stats statsFunc, fsStatsToMeasure []fsStats) cmpFunc { +func disk(stats statsFunc, fsStatsToMeasure []fsStatsType) cmpFunc { return func(p1, p2 *api.Pod) int { p1Stats, found := stats(p1) // if we have no usage stats for p1, we want p2 first @@ -489,7 +491,7 @@ func rankMemoryPressure(pods []*api.Pod, stats statsFunc) { } // rankDiskPressureFunc returns a rankFunc that measures the specified fs stats. -func rankDiskPressureFunc(fsStatsToMeasure []fsStats) rankFunc { +func rankDiskPressureFunc(fsStatsToMeasure []fsStatsType) rankFunc { return func(pods []*api.Pod, stats statsFunc) { orderedBy(qosComparator, disk(stats, fsStatsToMeasure)).Sort(pods) } @@ -622,8 +624,8 @@ func nodeConditionsObservedSince(observedAt nodeConditionsObservedAt, period tim return results } -// hgasFsStats returns true if the fsStat is in the input list -func hasFsStats(inputs []fsStats, item fsStats) bool { +// hasFsStatsType returns true if the fsStat is in the input list +func hasFsStatsType(inputs []fsStatsType, item fsStatsType) bool { for _, input := range inputs { if input == item { return true @@ -676,7 +678,7 @@ func isSoftEviction(thresholds []Threshold, starvedResource api.ResourceName) bo return true } -// buildresourceToRankFunc returns ranking functions associated with resources +// buildResourceToRankFunc returns ranking functions associated with resources func buildResourceToRankFunc(withImageFs bool) map[api.ResourceName]rankFunc { resourceToRankFunc := map[api.ResourceName]rankFunc{ api.ResourceMemory: rankMemoryPressure, @@ -684,12 +686,12 @@ func buildResourceToRankFunc(withImageFs bool) map[api.ResourceName]rankFunc { // usage of an imagefs is optional if withImageFs { // with an imagefs, nodefs pod rank func for eviction only includes logs and local volumes - resourceToRankFunc[resourceNodeFs] = rankDiskPressureFunc([]fsStats{fsStatsLogs, fsStatsLocalVolumeSource}) + resourceToRankFunc[resourceNodeFs] = rankDiskPressureFunc([]fsStatsType{fsStatsLogs, fsStatsLocalVolumeSource}) // with an imagefs, imagefs pod rank func for eviction only includes rootfs - resourceToRankFunc[resourceImageFs] = rankDiskPressureFunc([]fsStats{fsStatsRoot}) + resourceToRankFunc[resourceImageFs] = rankDiskPressureFunc([]fsStatsType{fsStatsRoot}) } else { // without an imagefs, nodefs pod rank func for eviction looks at all fs stats - resourceToRankFunc[resourceNodeFs] = rankDiskPressureFunc([]fsStats{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}) + resourceToRankFunc[resourceNodeFs] = rankDiskPressureFunc([]fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}) } return resourceToRankFunc } diff --git a/pkg/kubelet/eviction/helpers_test.go b/pkg/kubelet/eviction/helpers_test.go index 8e17d5e52c7..93713ddb7f1 100644 --- a/pkg/kubelet/eviction/helpers_test.go +++ b/pkg/kubelet/eviction/helpers_test.go @@ -311,7 +311,7 @@ func TestOrderedByDisk(t *testing.T) { return result, found } pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6} - orderedBy(disk(statsFn, []fsStats{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource})).Sort(pods) + orderedBy(disk(statsFn, []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource})).Sort(pods) expected := []*api.Pod{pod6, pod5, pod4, pod3, pod2, pod1} for i := range expected { if pods[i] != expected[i] { @@ -377,7 +377,7 @@ func TestOrderedByQoSDisk(t *testing.T) { return result, found } pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6} - orderedBy(qosComparator, disk(statsFn, []fsStats{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource})).Sort(pods) + orderedBy(qosComparator, disk(statsFn, []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource})).Sort(pods) expected := []*api.Pod{pod2, pod1, pod4, pod3, pod6, pod5} for i := range expected { if pods[i] != expected[i] { diff --git a/pkg/kubelet/eviction/types.go b/pkg/kubelet/eviction/types.go index 295cdefd812..053c47809da 100644 --- a/pkg/kubelet/eviction/types.go +++ b/pkg/kubelet/eviction/types.go @@ -36,16 +36,16 @@ const ( SignalImageFsAvailable Signal = "imagefs.available" ) -// fsStats defines the types of filesystem stats to collect. -type fsStats string +// fsStatsType defines the types of filesystem stats to collect. +type fsStatsType string const ( // fsStatsLocalVolumeSource identifies stats for pod local volume sources. - fsStatsLocalVolumeSource fsStats = "localVolumeSource" + fsStatsLocalVolumeSource fsStatsType = "localVolumeSource" // fsStatsLogs identifies stats for pod logs. - fsStatsLogs fsStats = "logs" + fsStatsLogs fsStatsType = "logs" // fsStatsRoot identifies stats for pod container writable layers. - fsStatsRoot fsStats = "root" + fsStatsRoot fsStatsType = "root" ) // ThresholdOperator is the operator used to express a Threshold. diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go index b2104996ade..91959053aa1 100755 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go @@ -2965,7 +2965,7 @@ func TestPodSchedulesOnNodeWithDiskPressureCondition(t *testing.T) { } for _, test := range tests { - fits, err := CheckNodeDiskPressurePredicate(test.pod, test.nodeInfo) + fits, err := CheckNodeDiskPressurePredicate(test.pod, nil, test.nodeInfo) if fits != test.fits { t.Errorf("%s: expected %v got %v", test.name, test.fits, fits) }