mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Rename and add unit test for ImageSizes
This commit is contained in:
parent
d7c40cf69e
commit
096dda3768
@ -72,7 +72,7 @@ func calculateScoreFromSize(sumSize int64) int {
|
|||||||
func totalImageSize(nodeInfo *schedulercache.NodeInfo, containers []v1.Container) int64 {
|
func totalImageSize(nodeInfo *schedulercache.NodeInfo, containers []v1.Container) int64 {
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
imageSizes := nodeInfo.Images()
|
imageSizes := nodeInfo.ImageSizes()
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
if size, ok := imageSizes[container.Image]; ok {
|
if size, ok := imageSizes[container.Image]; ok {
|
||||||
total += size
|
total += size
|
||||||
|
@ -293,8 +293,8 @@ func (n *NodeInfo) UsedPorts() util.HostPortInfo {
|
|||||||
return n.usedPorts
|
return n.usedPorts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Images returns the image size information on this node.
|
// ImageSizes returns the image size information on this node.
|
||||||
func (n *NodeInfo) Images() map[string]int64 {
|
func (n *NodeInfo) ImageSizes() map[string]int64 {
|
||||||
if n == nil {
|
if n == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,46 @@ func TestSetMaxResource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImageSizes(t *testing.T) {
|
||||||
|
ni := fakeNodeInfo()
|
||||||
|
ni.node = &v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-node",
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
Images: []v1.ContainerImage{
|
||||||
|
{
|
||||||
|
Names: []string{
|
||||||
|
"gcr.io/10",
|
||||||
|
"gcr.io/10:v1",
|
||||||
|
},
|
||||||
|
SizeBytes: int64(10 * 1024 * 1024),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Names: []string{
|
||||||
|
"gcr.io/50",
|
||||||
|
"gcr.io/50:v1",
|
||||||
|
},
|
||||||
|
SizeBytes: int64(50 * 1024 * 1024),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ni.updateImageSizes()
|
||||||
|
expected := map[string]int64{
|
||||||
|
"gcr.io/10": 10 * 1024 * 1024,
|
||||||
|
"gcr.io/10:v1": 10 * 1024 * 1024,
|
||||||
|
"gcr.io/50": 50 * 1024 * 1024,
|
||||||
|
"gcr.io/50:v1": 50 * 1024 * 1024,
|
||||||
|
}
|
||||||
|
|
||||||
|
imageSizes := ni.ImageSizes()
|
||||||
|
if !reflect.DeepEqual(expected, imageSizes) {
|
||||||
|
t.Errorf("expected: %#v, got: %#v", expected, imageSizes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewNodeInfo(t *testing.T) {
|
func TestNewNodeInfo(t *testing.T) {
|
||||||
nodeName := "test-node"
|
nodeName := "test-node"
|
||||||
pods := []*v1.Pod{
|
pods := []*v1.Pod{
|
||||||
|
Loading…
Reference in New Issue
Block a user