mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
cmd/kubelet
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
statsapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/stats"
|
||||
"k8s.io/kubernetes/pkg/quota"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
@@ -397,20 +398,20 @@ func thresholdEqual(a Threshold, b Threshold) bool {
|
||||
|
||||
// TestOrderedByQoS ensures we order BestEffort < Burstable < Guaranteed
|
||||
func TestOrderedByQoS(t *testing.T) {
|
||||
bestEffort := newPod("best-effort", []api.Container{
|
||||
bestEffort := newPod("best-effort", []v1.Container{
|
||||
newContainer("best-effort", newResourceList("", ""), newResourceList("", "")),
|
||||
}, nil)
|
||||
burstable := newPod("burstable", []api.Container{
|
||||
burstable := newPod("burstable", []v1.Container{
|
||||
newContainer("burstable", newResourceList("100m", "100Mi"), newResourceList("200m", "200Mi")),
|
||||
}, nil)
|
||||
guaranteed := newPod("guaranteed", []api.Container{
|
||||
guaranteed := newPod("guaranteed", []v1.Container{
|
||||
newContainer("guaranteed", newResourceList("200m", "200Mi"), newResourceList("200m", "200Mi")),
|
||||
}, nil)
|
||||
|
||||
pods := []*api.Pod{guaranteed, burstable, bestEffort}
|
||||
pods := []*v1.Pod{guaranteed, burstable, bestEffort}
|
||||
orderedBy(qosComparator).Sort(pods)
|
||||
|
||||
expected := []*api.Pod{bestEffort, burstable, guaranteed}
|
||||
expected := []*v1.Pod{bestEffort, burstable, guaranteed}
|
||||
for i := range expected {
|
||||
if pods[i] != expected[i] {
|
||||
t.Errorf("Expected pod: %s, but got: %s", expected[i].Name, pods[i].Name)
|
||||
@@ -427,51 +428,51 @@ func TestOrderedbyInodes(t *testing.T) {
|
||||
}
|
||||
|
||||
// testOrderedByDisk ensures we order pods by greediest resource consumer
|
||||
func testOrderedByResource(t *testing.T, orderedByResource api.ResourceName,
|
||||
newPodStatsFunc func(pod *api.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats) {
|
||||
pod1 := newPod("best-effort-high", []api.Container{
|
||||
func testOrderedByResource(t *testing.T, orderedByResource v1.ResourceName,
|
||||
newPodStatsFunc func(pod *v1.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats) {
|
||||
pod1 := newPod("best-effort-high", []v1.Container{
|
||||
newContainer("best-effort-high", newResourceList("", ""), newResourceList("", "")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod2 := newPod("best-effort-low", []api.Container{
|
||||
pod2 := newPod("best-effort-low", []v1.Container{
|
||||
newContainer("best-effort-low", newResourceList("", ""), newResourceList("", "")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod3 := newPod("burstable-high", []api.Container{
|
||||
pod3 := newPod("burstable-high", []v1.Container{
|
||||
newContainer("burstable-high", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod4 := newPod("burstable-low", []api.Container{
|
||||
pod4 := newPod("burstable-low", []v1.Container{
|
||||
newContainer("burstable-low", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod5 := newPod("guaranteed-high", []api.Container{
|
||||
pod5 := newPod("guaranteed-high", []v1.Container{
|
||||
newContainer("guaranteed-high", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod6 := newPod("guaranteed-low", []api.Container{
|
||||
pod6 := newPod("guaranteed-low", []v1.Container{
|
||||
newContainer("guaranteed-low", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
stats := map[*api.Pod]statsapi.PodStats{
|
||||
stats := map[*v1.Pod]statsapi.PodStats{
|
||||
pod1: newPodStatsFunc(pod1, resource.MustParse("50Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 200Mi
|
||||
pod2: newPodStatsFunc(pod2, resource.MustParse("100Mi"), resource.MustParse("150Mi"), resource.MustParse("50Mi")), // 300Mi
|
||||
pod3: newPodStatsFunc(pod3, resource.MustParse("200Mi"), resource.MustParse("150Mi"), resource.MustParse("50Mi")), // 400Mi
|
||||
@@ -479,13 +480,13 @@ func testOrderedByResource(t *testing.T, orderedByResource api.ResourceName,
|
||||
pod5: newPodStatsFunc(pod5, resource.MustParse("400Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 550Mi
|
||||
pod6: newPodStatsFunc(pod6, resource.MustParse("500Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 650Mi
|
||||
}
|
||||
statsFn := func(pod *api.Pod) (statsapi.PodStats, bool) {
|
||||
statsFn := func(pod *v1.Pod) (statsapi.PodStats, bool) {
|
||||
result, found := stats[pod]
|
||||
return result, found
|
||||
}
|
||||
pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
pods := []*v1.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
orderedBy(disk(statsFn, []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}, orderedByResource)).Sort(pods)
|
||||
expected := []*api.Pod{pod6, pod5, pod4, pod3, pod2, pod1}
|
||||
expected := []*v1.Pod{pod6, pod5, pod4, pod3, pod2, pod1}
|
||||
for i := range expected {
|
||||
if pods[i] != expected[i] {
|
||||
t.Errorf("Expected pod[%d]: %s, but got: %s", i, expected[i].Name, pods[i].Name)
|
||||
@@ -502,51 +503,51 @@ func TestOrderedbyQoSInodes(t *testing.T) {
|
||||
}
|
||||
|
||||
// testOrderedByQoSDisk ensures we order pods by qos and then greediest resource consumer
|
||||
func testOrderedByQoSResource(t *testing.T, orderedByResource api.ResourceName,
|
||||
newPodStatsFunc func(pod *api.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats) {
|
||||
pod1 := newPod("best-effort-high", []api.Container{
|
||||
func testOrderedByQoSResource(t *testing.T, orderedByResource v1.ResourceName,
|
||||
newPodStatsFunc func(pod *v1.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats) {
|
||||
pod1 := newPod("best-effort-high", []v1.Container{
|
||||
newContainer("best-effort-high", newResourceList("", ""), newResourceList("", "")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod2 := newPod("best-effort-low", []api.Container{
|
||||
pod2 := newPod("best-effort-low", []v1.Container{
|
||||
newContainer("best-effort-low", newResourceList("", ""), newResourceList("", "")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod3 := newPod("burstable-high", []api.Container{
|
||||
pod3 := newPod("burstable-high", []v1.Container{
|
||||
newContainer("burstable-high", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod4 := newPod("burstable-low", []api.Container{
|
||||
pod4 := newPod("burstable-low", []v1.Container{
|
||||
newContainer("burstable-low", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod5 := newPod("guaranteed-high", []api.Container{
|
||||
pod5 := newPod("guaranteed-high", []v1.Container{
|
||||
newContainer("guaranteed-high", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
pod6 := newPod("guaranteed-low", []api.Container{
|
||||
pod6 := newPod("guaranteed-low", []v1.Container{
|
||||
newContainer("guaranteed-low", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, []api.Volume{
|
||||
newVolume("local-volume", api.VolumeSource{
|
||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||
}, []v1.Volume{
|
||||
newVolume("local-volume", v1.VolumeSource{
|
||||
EmptyDir: &v1.EmptyDirVolumeSource{},
|
||||
}),
|
||||
})
|
||||
stats := map[*api.Pod]statsapi.PodStats{
|
||||
stats := map[*v1.Pod]statsapi.PodStats{
|
||||
pod1: newPodStatsFunc(pod1, resource.MustParse("50Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 200Mi
|
||||
pod2: newPodStatsFunc(pod2, resource.MustParse("100Mi"), resource.MustParse("150Mi"), resource.MustParse("50Mi")), // 300Mi
|
||||
pod3: newPodStatsFunc(pod3, resource.MustParse("200Mi"), resource.MustParse("150Mi"), resource.MustParse("50Mi")), // 400Mi
|
||||
@@ -554,13 +555,13 @@ func testOrderedByQoSResource(t *testing.T, orderedByResource api.ResourceName,
|
||||
pod5: newPodStatsFunc(pod5, resource.MustParse("400Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 550Mi
|
||||
pod6: newPodStatsFunc(pod6, resource.MustParse("500Mi"), resource.MustParse("100Mi"), resource.MustParse("50Mi")), // 650Mi
|
||||
}
|
||||
statsFn := func(pod *api.Pod) (statsapi.PodStats, bool) {
|
||||
statsFn := func(pod *v1.Pod) (statsapi.PodStats, bool) {
|
||||
result, found := stats[pod]
|
||||
return result, found
|
||||
}
|
||||
pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
pods := []*v1.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
orderedBy(qosComparator, disk(statsFn, []fsStatsType{fsStatsRoot, fsStatsLogs, fsStatsLocalVolumeSource}, orderedByResource)).Sort(pods)
|
||||
expected := []*api.Pod{pod2, pod1, pod4, pod3, pod6, pod5}
|
||||
expected := []*v1.Pod{pod2, pod1, pod4, pod3, pod6, pod5}
|
||||
for i := range expected {
|
||||
if pods[i] != expected[i] {
|
||||
t.Errorf("Expected pod[%d]: %s, but got: %s", i, expected[i].Name, pods[i].Name)
|
||||
@@ -570,25 +571,25 @@ func testOrderedByQoSResource(t *testing.T, orderedByResource api.ResourceName,
|
||||
|
||||
// TestOrderedByMemory ensures we order pods by greediest memory consumer relative to request.
|
||||
func TestOrderedByMemory(t *testing.T) {
|
||||
pod1 := newPod("best-effort-high", []api.Container{
|
||||
pod1 := newPod("best-effort-high", []v1.Container{
|
||||
newContainer("best-effort-high", newResourceList("", ""), newResourceList("", "")),
|
||||
}, nil)
|
||||
pod2 := newPod("best-effort-low", []api.Container{
|
||||
pod2 := newPod("best-effort-low", []v1.Container{
|
||||
newContainer("best-effort-low", newResourceList("", ""), newResourceList("", "")),
|
||||
}, nil)
|
||||
pod3 := newPod("burstable-high", []api.Container{
|
||||
pod3 := newPod("burstable-high", []v1.Container{
|
||||
newContainer("burstable-high", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, nil)
|
||||
pod4 := newPod("burstable-low", []api.Container{
|
||||
pod4 := newPod("burstable-low", []v1.Container{
|
||||
newContainer("burstable-low", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, nil)
|
||||
pod5 := newPod("guaranteed-high", []api.Container{
|
||||
pod5 := newPod("guaranteed-high", []v1.Container{
|
||||
newContainer("guaranteed-high", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, nil)
|
||||
pod6 := newPod("guaranteed-low", []api.Container{
|
||||
pod6 := newPod("guaranteed-low", []v1.Container{
|
||||
newContainer("guaranteed-low", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, nil)
|
||||
stats := map[*api.Pod]statsapi.PodStats{
|
||||
stats := map[*v1.Pod]statsapi.PodStats{
|
||||
pod1: newPodMemoryStats(pod1, resource.MustParse("500Mi")), // 500 relative to request
|
||||
pod2: newPodMemoryStats(pod2, resource.MustParse("300Mi")), // 300 relative to request
|
||||
pod3: newPodMemoryStats(pod3, resource.MustParse("800Mi")), // 700 relative to request
|
||||
@@ -596,13 +597,13 @@ func TestOrderedByMemory(t *testing.T) {
|
||||
pod5: newPodMemoryStats(pod5, resource.MustParse("800Mi")), // -200 relative to request
|
||||
pod6: newPodMemoryStats(pod6, resource.MustParse("200Mi")), // -800 relative to request
|
||||
}
|
||||
statsFn := func(pod *api.Pod) (statsapi.PodStats, bool) {
|
||||
statsFn := func(pod *v1.Pod) (statsapi.PodStats, bool) {
|
||||
result, found := stats[pod]
|
||||
return result, found
|
||||
}
|
||||
pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
pods := []*v1.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
orderedBy(memory(statsFn)).Sort(pods)
|
||||
expected := []*api.Pod{pod3, pod1, pod2, pod4, pod5, pod6}
|
||||
expected := []*v1.Pod{pod3, pod1, pod2, pod4, pod5, pod6}
|
||||
for i := range expected {
|
||||
if pods[i] != expected[i] {
|
||||
t.Errorf("Expected pod[%d]: %s, but got: %s", i, expected[i].Name, pods[i].Name)
|
||||
@@ -612,25 +613,25 @@ func TestOrderedByMemory(t *testing.T) {
|
||||
|
||||
// TestOrderedByQoSMemory ensures we order by qosComparator and then memory consumption relative to request.
|
||||
func TestOrderedByQoSMemory(t *testing.T) {
|
||||
pod1 := newPod("best-effort-high", []api.Container{
|
||||
pod1 := newPod("best-effort-high", []v1.Container{
|
||||
newContainer("best-effort-high", newResourceList("", ""), newResourceList("", "")),
|
||||
}, nil)
|
||||
pod2 := newPod("best-effort-low", []api.Container{
|
||||
pod2 := newPod("best-effort-low", []v1.Container{
|
||||
newContainer("best-effort-low", newResourceList("", ""), newResourceList("", "")),
|
||||
}, nil)
|
||||
pod3 := newPod("burstable-high", []api.Container{
|
||||
pod3 := newPod("burstable-high", []v1.Container{
|
||||
newContainer("burstable-high", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, nil)
|
||||
pod4 := newPod("burstable-low", []api.Container{
|
||||
pod4 := newPod("burstable-low", []v1.Container{
|
||||
newContainer("burstable-low", newResourceList("100m", "100Mi"), newResourceList("200m", "1Gi")),
|
||||
}, nil)
|
||||
pod5 := newPod("guaranteed-high", []api.Container{
|
||||
pod5 := newPod("guaranteed-high", []v1.Container{
|
||||
newContainer("guaranteed-high", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, nil)
|
||||
pod6 := newPod("guaranteed-low", []api.Container{
|
||||
pod6 := newPod("guaranteed-low", []v1.Container{
|
||||
newContainer("guaranteed-low", newResourceList("100m", "1Gi"), newResourceList("100m", "1Gi")),
|
||||
}, nil)
|
||||
stats := map[*api.Pod]statsapi.PodStats{
|
||||
stats := map[*v1.Pod]statsapi.PodStats{
|
||||
pod1: newPodMemoryStats(pod1, resource.MustParse("500Mi")), // 500 relative to request
|
||||
pod2: newPodMemoryStats(pod2, resource.MustParse("50Mi")), // 50 relative to request
|
||||
pod3: newPodMemoryStats(pod3, resource.MustParse("50Mi")), // -50 relative to request
|
||||
@@ -638,12 +639,12 @@ func TestOrderedByQoSMemory(t *testing.T) {
|
||||
pod5: newPodMemoryStats(pod5, resource.MustParse("800Mi")), // -200 relative to request
|
||||
pod6: newPodMemoryStats(pod6, resource.MustParse("200Mi")), // -800 relative to request
|
||||
}
|
||||
statsFn := func(pod *api.Pod) (statsapi.PodStats, bool) {
|
||||
statsFn := func(pod *v1.Pod) (statsapi.PodStats, bool) {
|
||||
result, found := stats[pod]
|
||||
return result, found
|
||||
}
|
||||
pods := []*api.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
expected := []*api.Pod{pod1, pod2, pod4, pod3, pod5, pod6}
|
||||
pods := []*v1.Pod{pod1, pod2, pod3, pod4, pod5, pod6}
|
||||
expected := []*v1.Pod{pod1, pod2, pod4, pod3, pod5, pod6}
|
||||
orderedBy(qosComparator, memory(statsFn)).Sort(pods)
|
||||
for i := range expected {
|
||||
if pods[i] != expected[i] {
|
||||
@@ -662,7 +663,7 @@ func (f *fakeSummaryProvider) Get() (*statsapi.Summary, error) {
|
||||
|
||||
// newPodStats returns a pod stat where each container is using the specified working set
|
||||
// each pod must have a Name, UID, Namespace
|
||||
func newPodStats(pod *api.Pod, containerWorkingSetBytes int64) statsapi.PodStats {
|
||||
func newPodStats(pod *v1.Pod, containerWorkingSetBytes int64) statsapi.PodStats {
|
||||
result := statsapi.PodStats{
|
||||
PodRef: statsapi.PodReference{
|
||||
Name: pod.Name,
|
||||
@@ -682,14 +683,14 @@ func newPodStats(pod *api.Pod, containerWorkingSetBytes int64) statsapi.PodStats
|
||||
}
|
||||
|
||||
func TestMakeSignalObservations(t *testing.T) {
|
||||
podMaker := func(name, namespace, uid string, numContainers int) *api.Pod {
|
||||
pod := &api.Pod{}
|
||||
podMaker := func(name, namespace, uid string, numContainers int) *v1.Pod {
|
||||
pod := &v1.Pod{}
|
||||
pod.Name = name
|
||||
pod.Namespace = namespace
|
||||
pod.UID = types.UID(uid)
|
||||
pod.Spec = api.PodSpec{}
|
||||
pod.Spec = v1.PodSpec{}
|
||||
for i := 0; i < numContainers; i++ {
|
||||
pod.Spec.Containers = append(pod.Spec.Containers, api.Container{
|
||||
pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{
|
||||
Name: fmt.Sprintf("ctr%v", i),
|
||||
})
|
||||
}
|
||||
@@ -731,7 +732,7 @@ func TestMakeSignalObservations(t *testing.T) {
|
||||
provider := &fakeSummaryProvider{
|
||||
result: fakeStats,
|
||||
}
|
||||
pods := []*api.Pod{
|
||||
pods := []*v1.Pod{
|
||||
podMaker("pod1", "ns1", "uuid1", 1),
|
||||
podMaker("pod1", "ns2", "uuid2", 1),
|
||||
podMaker("pod3", "ns3", "uuid3", 1),
|
||||
@@ -1199,17 +1200,17 @@ func TestThresholdsMetGracePeriod(t *testing.T) {
|
||||
func TestNodeConditions(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
inputs []Threshold
|
||||
result []api.NodeConditionType
|
||||
result []v1.NodeConditionType
|
||||
}{
|
||||
"empty-list": {
|
||||
inputs: []Threshold{},
|
||||
result: []api.NodeConditionType{},
|
||||
result: []v1.NodeConditionType{},
|
||||
},
|
||||
"memory.available": {
|
||||
inputs: []Threshold{
|
||||
{Signal: SignalMemoryAvailable},
|
||||
},
|
||||
result: []api.NodeConditionType{api.NodeMemoryPressure},
|
||||
result: []v1.NodeConditionType{v1.NodeMemoryPressure},
|
||||
},
|
||||
}
|
||||
for testName, testCase := range testCases {
|
||||
@@ -1224,37 +1225,37 @@ func TestNodeConditionsLastObservedAt(t *testing.T) {
|
||||
now := unversioned.Now()
|
||||
oldTime := unversioned.NewTime(now.Time.Add(-1 * time.Minute))
|
||||
testCases := map[string]struct {
|
||||
nodeConditions []api.NodeConditionType
|
||||
nodeConditions []v1.NodeConditionType
|
||||
lastObservedAt nodeConditionsObservedAt
|
||||
now time.Time
|
||||
result nodeConditionsObservedAt
|
||||
}{
|
||||
"no-previous-observation": {
|
||||
nodeConditions: []api.NodeConditionType{api.NodeMemoryPressure},
|
||||
nodeConditions: []v1.NodeConditionType{v1.NodeMemoryPressure},
|
||||
lastObservedAt: nodeConditionsObservedAt{},
|
||||
now: now.Time,
|
||||
result: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: now.Time,
|
||||
v1.NodeMemoryPressure: now.Time,
|
||||
},
|
||||
},
|
||||
"previous-observation": {
|
||||
nodeConditions: []api.NodeConditionType{api.NodeMemoryPressure},
|
||||
nodeConditions: []v1.NodeConditionType{v1.NodeMemoryPressure},
|
||||
lastObservedAt: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: oldTime.Time,
|
||||
v1.NodeMemoryPressure: oldTime.Time,
|
||||
},
|
||||
now: now.Time,
|
||||
result: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: now.Time,
|
||||
v1.NodeMemoryPressure: now.Time,
|
||||
},
|
||||
},
|
||||
"old-observation": {
|
||||
nodeConditions: []api.NodeConditionType{},
|
||||
nodeConditions: []v1.NodeConditionType{},
|
||||
lastObservedAt: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: oldTime.Time,
|
||||
v1.NodeMemoryPressure: oldTime.Time,
|
||||
},
|
||||
now: now.Time,
|
||||
result: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: oldTime.Time,
|
||||
v1.NodeMemoryPressure: oldTime.Time,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1273,23 +1274,23 @@ func TestNodeConditionsObservedSince(t *testing.T) {
|
||||
observedAt nodeConditionsObservedAt
|
||||
period time.Duration
|
||||
now time.Time
|
||||
result []api.NodeConditionType
|
||||
result []v1.NodeConditionType
|
||||
}{
|
||||
"in-period": {
|
||||
observedAt: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: observedTime.Time,
|
||||
v1.NodeMemoryPressure: observedTime.Time,
|
||||
},
|
||||
period: 2 * time.Minute,
|
||||
now: now.Time,
|
||||
result: []api.NodeConditionType{api.NodeMemoryPressure},
|
||||
result: []v1.NodeConditionType{v1.NodeMemoryPressure},
|
||||
},
|
||||
"out-of-period": {
|
||||
observedAt: nodeConditionsObservedAt{
|
||||
api.NodeMemoryPressure: observedTime.Time,
|
||||
v1.NodeMemoryPressure: observedTime.Time,
|
||||
},
|
||||
period: 30 * time.Second,
|
||||
now: now.Time,
|
||||
result: []api.NodeConditionType{},
|
||||
result: []v1.NodeConditionType{},
|
||||
},
|
||||
}
|
||||
for testName, testCase := range testCases {
|
||||
@@ -1302,18 +1303,18 @@ func TestNodeConditionsObservedSince(t *testing.T) {
|
||||
|
||||
func TestHasNodeConditions(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
inputs []api.NodeConditionType
|
||||
item api.NodeConditionType
|
||||
inputs []v1.NodeConditionType
|
||||
item v1.NodeConditionType
|
||||
result bool
|
||||
}{
|
||||
"has-condition": {
|
||||
inputs: []api.NodeConditionType{api.NodeReady, api.NodeOutOfDisk, api.NodeMemoryPressure},
|
||||
item: api.NodeMemoryPressure,
|
||||
inputs: []v1.NodeConditionType{v1.NodeReady, v1.NodeOutOfDisk, v1.NodeMemoryPressure},
|
||||
item: v1.NodeMemoryPressure,
|
||||
result: true,
|
||||
},
|
||||
"does-not-have-condition": {
|
||||
inputs: []api.NodeConditionType{api.NodeReady, api.NodeOutOfDisk},
|
||||
item: api.NodeMemoryPressure,
|
||||
inputs: []v1.NodeConditionType{v1.NodeReady, v1.NodeOutOfDisk},
|
||||
item: v1.NodeMemoryPressure,
|
||||
result: false,
|
||||
},
|
||||
}
|
||||
@@ -1327,31 +1328,38 @@ func TestHasNodeConditions(t *testing.T) {
|
||||
func TestGetStarvedResources(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
inputs []Threshold
|
||||
result []api.ResourceName
|
||||
result []v1.ResourceName
|
||||
}{
|
||||
"memory.available": {
|
||||
inputs: []Threshold{
|
||||
{Signal: SignalMemoryAvailable},
|
||||
},
|
||||
result: []api.ResourceName{api.ResourceMemory},
|
||||
result: []v1.ResourceName{v1.ResourceMemory},
|
||||
},
|
||||
"imagefs.available": {
|
||||
inputs: []Threshold{
|
||||
{Signal: SignalImageFsAvailable},
|
||||
},
|
||||
result: []api.ResourceName{resourceImageFs},
|
||||
result: []v1.ResourceName{resourceImageFs},
|
||||
},
|
||||
"nodefs.available": {
|
||||
inputs: []Threshold{
|
||||
{Signal: SignalNodeFsAvailable},
|
||||
},
|
||||
result: []api.ResourceName{resourceNodeFs},
|
||||
result: []v1.ResourceName{resourceNodeFs},
|
||||
},
|
||||
}
|
||||
var internalResourceNames = func(in []v1.ResourceName) []api.ResourceName {
|
||||
var out []api.ResourceName
|
||||
for _, name := range in {
|
||||
out = append(out, api.ResourceName(name))
|
||||
}
|
||||
return out
|
||||
}
|
||||
for testName, testCase := range testCases {
|
||||
actual := getStarvedResources(testCase.inputs)
|
||||
actualSet := quota.ToSet(actual)
|
||||
expectedSet := quota.ToSet(testCase.result)
|
||||
actualSet := quota.ToSet(internalResourceNames(actual))
|
||||
expectedSet := quota.ToSet(internalResourceNames(testCase.result))
|
||||
if !actualSet.Equal(expectedSet) {
|
||||
t.Errorf("Test case: %s, expected: %v, actual: %v", testName, expectedSet, actualSet)
|
||||
}
|
||||
@@ -1448,7 +1456,7 @@ func testCompareThresholdValue(t *testing.T) {
|
||||
}
|
||||
|
||||
// newPodInodeStats returns stats with specified usage amounts.
|
||||
func newPodInodeStats(pod *api.Pod, rootFsInodesUsed, logsInodesUsed, perLocalVolumeInodesUsed resource.Quantity) statsapi.PodStats {
|
||||
func newPodInodeStats(pod *v1.Pod, rootFsInodesUsed, logsInodesUsed, perLocalVolumeInodesUsed resource.Quantity) statsapi.PodStats {
|
||||
result := statsapi.PodStats{
|
||||
PodRef: statsapi.PodReference{
|
||||
Name: pod.Name, Namespace: pod.Namespace, UID: string(pod.UID),
|
||||
@@ -1480,7 +1488,7 @@ func newPodInodeStats(pod *api.Pod, rootFsInodesUsed, logsInodesUsed, perLocalVo
|
||||
}
|
||||
|
||||
// newPodDiskStats returns stats with specified usage amounts.
|
||||
func newPodDiskStats(pod *api.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats {
|
||||
func newPodDiskStats(pod *v1.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats {
|
||||
result := statsapi.PodStats{
|
||||
PodRef: statsapi.PodReference{
|
||||
Name: pod.Name, Namespace: pod.Namespace, UID: string(pod.UID),
|
||||
@@ -1513,7 +1521,7 @@ func newPodDiskStats(pod *api.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed reso
|
||||
return result
|
||||
}
|
||||
|
||||
func newPodMemoryStats(pod *api.Pod, workingSet resource.Quantity) statsapi.PodStats {
|
||||
func newPodMemoryStats(pod *v1.Pod, workingSet resource.Quantity) statsapi.PodStats {
|
||||
result := statsapi.PodStats{
|
||||
PodRef: statsapi.PodReference{
|
||||
Name: pod.Name, Namespace: pod.Namespace, UID: string(pod.UID),
|
||||
@@ -1530,46 +1538,46 @@ func newPodMemoryStats(pod *api.Pod, workingSet resource.Quantity) statsapi.PodS
|
||||
return result
|
||||
}
|
||||
|
||||
func newResourceList(cpu, memory string) api.ResourceList {
|
||||
res := api.ResourceList{}
|
||||
func newResourceList(cpu, memory string) v1.ResourceList {
|
||||
res := v1.ResourceList{}
|
||||
if cpu != "" {
|
||||
res[api.ResourceCPU] = resource.MustParse(cpu)
|
||||
res[v1.ResourceCPU] = resource.MustParse(cpu)
|
||||
}
|
||||
if memory != "" {
|
||||
res[api.ResourceMemory] = resource.MustParse(memory)
|
||||
res[v1.ResourceMemory] = resource.MustParse(memory)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func newResourceRequirements(requests, limits api.ResourceList) api.ResourceRequirements {
|
||||
res := api.ResourceRequirements{}
|
||||
func newResourceRequirements(requests, limits v1.ResourceList) v1.ResourceRequirements {
|
||||
res := v1.ResourceRequirements{}
|
||||
res.Requests = requests
|
||||
res.Limits = limits
|
||||
return res
|
||||
}
|
||||
|
||||
func newContainer(name string, requests api.ResourceList, limits api.ResourceList) api.Container {
|
||||
return api.Container{
|
||||
func newContainer(name string, requests v1.ResourceList, limits v1.ResourceList) v1.Container {
|
||||
return v1.Container{
|
||||
Name: name,
|
||||
Resources: newResourceRequirements(requests, limits),
|
||||
}
|
||||
}
|
||||
|
||||
func newVolume(name string, volumeSource api.VolumeSource) api.Volume {
|
||||
return api.Volume{
|
||||
func newVolume(name string, volumeSource v1.VolumeSource) v1.Volume {
|
||||
return v1.Volume{
|
||||
Name: name,
|
||||
VolumeSource: volumeSource,
|
||||
}
|
||||
}
|
||||
|
||||
// newPod uses the name as the uid. Make names unique for testing.
|
||||
func newPod(name string, containers []api.Container, volumes []api.Volume) *api.Pod {
|
||||
return &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
func newPod(name string, containers []v1.Container, volumes []v1.Volume) *v1.Pod {
|
||||
return &v1.Pod{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: name,
|
||||
UID: types.UID(name),
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: containers,
|
||||
Volumes: volumes,
|
||||
},
|
||||
@@ -1577,7 +1585,7 @@ func newPod(name string, containers []api.Container, volumes []api.Volume) *api.
|
||||
}
|
||||
|
||||
// nodeConditionList is a simple alias to support equality checking independent of order
|
||||
type nodeConditionList []api.NodeConditionType
|
||||
type nodeConditionList []v1.NodeConditionType
|
||||
|
||||
// Equal adds the ability to check equality between two lists of node conditions.
|
||||
func (s1 nodeConditionList) Equal(s2 nodeConditionList) bool {
|
||||
|
||||
Reference in New Issue
Block a user