From b4b108418cf2213af6d8658d176f4b20dc1b497a Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 20 Oct 2017 18:46:25 +0200 Subject: [PATCH] UPSTREAM: 54308: The garbage collector creates too many pods --- .../kubernetes/test/e2e/garbage_collector.go | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/vendor/k8s.io/kubernetes/test/e2e/garbage_collector.go b/vendor/k8s.io/kubernetes/test/e2e/garbage_collector.go index 94d851c73594..b310b28348e4 100644 --- a/vendor/k8s.io/kubernetes/test/e2e/garbage_collector.go +++ b/vendor/k8s.io/kubernetes/test/e2e/garbage_collector.go @@ -35,6 +35,27 @@ import ( . "github.com/onsi/gomega" ) +// estimateMaximumPods estimates how many pods the cluster can handle +// with some wiggle room, to prevent pods being unable to schedule due +// to max pod constraints. +func estimateMaximumPods(c clientset.Interface) int32 { + availablePods := int32(0) + for _, node := range framework.GetReadySchedulableNodesOrDie(c).Items { + if q, ok := node.Status.Allocatable["pods"]; ok { + if num, ok := q.AsInt64(); ok { + availablePods += int32(num) * 8 / 10 + continue + } + } + // best guess + availablePods += 8 + } + if availablePods > 100 { + availablePods = 100 + } + return availablePods +} + func getForegroundOptions() *metav1.DeleteOptions { policy := metav1.DeletePropagationForeground return &metav1.DeleteOptions{PropagationPolicy: &policy} @@ -275,7 +296,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() { rcClient := clientSet.Core().ReplicationControllers(f.Namespace.Name) podClient := clientSet.Core().Pods(f.Namespace.Name) rcName := "simpletest.rc" - rc := newOwnerRC(f, rcName, 100) + rc := newOwnerRC(f, rcName, estimateMaximumPods(clientSet)) By("create the rc") rc, err := rcClient.Create(rc) if err != nil { @@ -500,7 +521,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() { rcClient := clientSet.Core().ReplicationControllers(f.Namespace.Name) podClient := clientSet.Core().Pods(f.Namespace.Name) rcName := "simpletest.rc" - rc := newOwnerRC(f, rcName, 100) + rc := newOwnerRC(f, rcName, estimateMaximumPods(clientSet)) By("create the rc") rc, err := rcClient.Create(rc) if err != nil { @@ -578,7 +599,7 @@ var _ = framework.KubeDescribe("Garbage collector", func() { rcClient := clientSet.Core().ReplicationControllers(f.Namespace.Name) podClient := clientSet.Core().Pods(f.Namespace.Name) rc1Name := "simpletest-rc-to-be-deleted" - replicas := int32(100) + replicas := int32(estimateMaximumPods(clientSet)) halfReplicas := int(replicas / 2) rc1 := newOwnerRC(f, rc1Name, replicas) By("create the rc1")