mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #16156 from piosz/hpa-test
Improved HPA e2e to test stability of the scale decision
This commit is contained in:
commit
c389897017
@ -231,6 +231,17 @@ func (rc *ResourceConsumer) WaitForReplicas(desiredReplicas int) {
|
||||
Failf("timeout waiting %v for pods size to be %d", timeout, desiredReplicas)
|
||||
}
|
||||
|
||||
func (rc *ResourceConsumer) EnsureDesiredReplicas(desiredReplicas int, timeout time.Duration) {
|
||||
for start := time.Now(); time.Since(start) < timeout; time.Sleep(10 * time.Second) {
|
||||
actual := rc.GetReplicas()
|
||||
if desiredReplicas != actual {
|
||||
Failf("Number of replicas has changed: expected %v, got %v", desiredReplicas, actual)
|
||||
}
|
||||
Logf("Number of replicas is as expected")
|
||||
}
|
||||
Logf("Number of replicas was stable over %v", timeout)
|
||||
}
|
||||
|
||||
func (rc *ResourceConsumer) CleanUp() {
|
||||
By(fmt.Sprintf("Removing consuming RC %s", rc.name))
|
||||
rc.stopCPU <- 0
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
|
||||
@ -24,8 +26,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
kind = "replicationController"
|
||||
subresource = "scale"
|
||||
kind = "replicationController"
|
||||
subresource = "scale"
|
||||
stabilityTimeout = 10 * time.Minute
|
||||
)
|
||||
|
||||
var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
@ -38,6 +41,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
defer rc.CleanUp()
|
||||
createCPUHorizontalPodAutoscaler(rc, 20)
|
||||
rc.WaitForReplicas(3)
|
||||
rc.EnsureDesiredReplicas(3, stabilityTimeout)
|
||||
rc.ConsumeCPU(700)
|
||||
rc.WaitForReplicas(5)
|
||||
})
|
||||
@ -47,6 +51,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
||||
defer rc.CleanUp()
|
||||
createCPUHorizontalPodAutoscaler(rc, 30)
|
||||
rc.WaitForReplicas(3)
|
||||
rc.EnsureDesiredReplicas(3, stabilityTimeout)
|
||||
rc.ConsumeCPU(100)
|
||||
rc.WaitForReplicas(1)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user