mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Only store top N images in status
This commit is contained in:
parent
f538d6019d
commit
032a886320
@ -151,6 +151,9 @@ const (
|
||||
|
||||
// Maximum period to wait for pod volume setup operations
|
||||
maxWaitForVolumeOps = 20 * time.Minute
|
||||
|
||||
// maxImagesInStatus is the number of max images we store in image status.
|
||||
maxImagesInNodeStatus = 50
|
||||
)
|
||||
|
||||
// SyncHandler is an interface implemented by Kubelet, for testability
|
||||
@ -3096,6 +3099,12 @@ func (kl *Kubelet) setNodeStatusImages(node *api.Node) {
|
||||
if err != nil {
|
||||
glog.Errorf("Error getting image list: %v", err)
|
||||
} else {
|
||||
// sort the images from max to min, and only set top N images into the node status.
|
||||
sort.Sort(ByImageSize(containerImages))
|
||||
if maxImagesInNodeStatus < len(containerImages) {
|
||||
containerImages = containerImages[0 : maxImagesInNodeStatus-1]
|
||||
}
|
||||
|
||||
for _, image := range containerImages {
|
||||
imagesOnNode = append(imagesOnNode, api.ContainerImage{
|
||||
Names: append(image.RepoTags, image.RepoDigests...),
|
||||
@ -3112,6 +3121,15 @@ func (kl *Kubelet) setNodeStatusGoRuntime(node *api.Node) {
|
||||
node.Status.NodeInfo.Architecture = goRuntime.GOARCH
|
||||
}
|
||||
|
||||
type ByImageSize []kubecontainer.Image
|
||||
|
||||
// Sort from max to min
|
||||
func (a ByImageSize) Less(i, j int) bool {
|
||||
return a[i].Size > a[j].Size
|
||||
}
|
||||
func (a ByImageSize) Len() int { return len(a) }
|
||||
func (a ByImageSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
// Set status for the node.
|
||||
func (kl *Kubelet) setNodeStatusInfo(node *api.Node) {
|
||||
kl.setNodeStatusMachineInfo(node)
|
||||
|
@ -2435,14 +2435,14 @@ func TestUpdateNewNodeStatus(t *testing.T) {
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
},
|
||||
Images: []api.ContainerImage{
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v3", "gcr.io/google_containers:v4"},
|
||||
SizeBytes: 456,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -2685,15 +2685,16 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
||||
{Type: api.NodeLegacyHostIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
},
|
||||
// images will be sorted from max to min in node status.
|
||||
Images: []api.ContainerImage{
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v3", "gcr.io/google_containers:v4"},
|
||||
SizeBytes: 456,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -2969,14 +2970,14 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) {
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
},
|
||||
Images: []api.ContainerImage{
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v3", "gcr.io/google_containers:v4"},
|
||||
SizeBytes: 456,
|
||||
},
|
||||
{
|
||||
Names: []string{"gcr.io/google_containers:v1", "gcr.io/google_containers:v2"},
|
||||
SizeBytes: 123,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user