Merge pull request #32914 from yujuhong/limit_names

Automatic merge from submit-queue

Limit the number of names per image reported in the node status

This fixes #32908
This commit is contained in:
Kubernetes Submit Queue 2016-09-19 15:10:52 -07:00 committed by GitHub
commit 30ff1f495a
4 changed files with 23 additions and 8 deletions

View File

@ -157,9 +157,6 @@ const (
// Period for performing image garbage collection.
ImageGCPeriod = 5 * time.Minute
// maxImagesInStatus is the number of max images we store in image status.
maxImagesInNodeStatus = 50
// Minimum number of dead containers to keep in a pod
minDeadContainerInPod = 1
)

View File

@ -39,6 +39,15 @@ import (
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
const (
// maxImagesInNodeStatus is the number of max images we store in image status.
maxImagesInNodeStatus = 50
// maxNamesPerImageInNodeStatus is max number of names per image stored in
// the node status.
maxNamesPerImageInNodeStatus = 5
)
// registerWithApiServer registers the node with the cluster master. It is safe
// to call multiple times, but not concurrently (kl.registrationCompleted is
// not locked).
@ -501,8 +510,13 @@ func (kl *Kubelet) setNodeStatusImages(node *api.Node) {
}
for _, image := range containerImages {
names := append(image.RepoDigests, image.RepoTags...)
// Report up to maxNamesPerImageInNodeStatus names per image.
if len(names) > maxNamesPerImageInNodeStatus {
names = names[0:maxNamesPerImageInNodeStatus]
}
imagesOnNode = append(imagesOnNode, api.ContainerImage{
Names: append(image.RepoTags, image.RepoDigests...),
Names: names,
SizeBytes: image.Size,
})
}

View File

@ -44,6 +44,10 @@ import (
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
const (
maxImageTagsForTest = 20
)
// generateTestingImageList generate randomly generated image list and corresponding expectedImageList.
func generateTestingImageList(count int) ([]kubecontainer.Image, []api.ContainerImage) {
// imageList is randomly generated image list
@ -64,7 +68,7 @@ func generateTestingImageList(count int) ([]kubecontainer.Image, []api.Container
var expectedImageList []api.ContainerImage
for _, kubeImage := range imageList {
apiImage := api.ContainerImage{
Names: kubeImage.RepoTags,
Names: kubeImage.RepoTags[0:maxNamesPerImageInNodeStatus],
SizeBytes: kubeImage.Size,
}
@ -76,7 +80,9 @@ func generateTestingImageList(count int) ([]kubecontainer.Image, []api.Container
func generateImageTags() []string {
var tagList []string
count := rand.IntnRange(1, maxImageTagsForTest+1)
// Generate > maxNamesPerImageInNodeStatus tags so that the test can verify
// that kubelet report up to maxNamesPerImageInNodeStatus tags.
count := rand.IntnRange(maxNamesPerImageInNodeStatus+1, maxImageTagsForTest+1)
for ; count > 0; count-- {
tagList = append(tagList, "gcr.io/google_containers:v"+strconv.Itoa(count))
}

View File

@ -86,8 +86,6 @@ const (
testReservationCPU = "200m"
testReservationMemory = "100M"
maxImageTagsForTest = 3
// TODO(harry) any global place for these two?
// Reasonable size range of all container images. 90%ile of images on dockerhub drops into this range.
minImgSize int64 = 23 * 1024 * 1024