2015-09-07 10:26:23 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors.
|
2015-09-07 10:26:23 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-04-03 13:42:15 +00:00
|
|
|
package autoscaling
|
2015-09-07 10:26:23 +00:00
|
|
|
|
|
|
|
import (
|
2015-10-27 08:44:05 +00:00
|
|
|
"time"
|
|
|
|
|
2017-10-25 21:08:52 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
2017-02-15 14:37:36 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/common"
|
2016-04-07 17:21:31 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2015-10-16 08:50:36 +00:00
|
|
|
|
2015-09-07 10:26:23 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
)
|
|
|
|
|
2016-01-29 19:05:58 +00:00
|
|
|
// These tests don't seem to be running properly in parallel: issue: #20338.
|
|
|
|
//
|
2017-08-01 12:06:11 +00:00
|
|
|
var _ = SIGDescribe("[HPA] Horizontal pod autoscaling (scale resource: CPU)", func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
var rc *common.ResourceConsumer
|
2016-04-07 17:21:31 +00:00
|
|
|
f := framework.NewDefaultFramework("horizontal-pod-autoscaling")
|
2015-09-07 10:26:23 +00:00
|
|
|
|
2016-06-13 07:45:30 +00:00
|
|
|
titleUp := "Should scale from 1 pod to 3 pods and from 3 to 5"
|
|
|
|
titleDown := "Should scale from 5 pods to 3 pods and from 3 to 1"
|
2015-10-30 13:48:32 +00:00
|
|
|
|
2017-08-01 12:06:11 +00:00
|
|
|
SIGDescribe("[Serial] [Slow] Deployment", func() {
|
2016-03-09 00:27:13 +00:00
|
|
|
// CPU tests via deployments
|
|
|
|
It(titleUp, func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleUp("test-deployment", common.KindDeployment, false, rc, f)
|
2016-03-09 00:27:13 +00:00
|
|
|
})
|
|
|
|
It(titleDown, func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleDown("test-deployment", common.KindDeployment, false, rc, f)
|
2016-03-09 00:27:13 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-08-01 12:06:11 +00:00
|
|
|
SIGDescribe("[Serial] [Slow] ReplicaSet", func() {
|
2018-07-27 07:12:16 +00:00
|
|
|
// CPU tests via ReplicaSets
|
2016-03-09 00:27:13 +00:00
|
|
|
It(titleUp, func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleUp("rs", common.KindReplicaSet, false, rc, f)
|
2016-03-09 00:27:13 +00:00
|
|
|
})
|
|
|
|
It(titleDown, func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleDown("rs", common.KindReplicaSet, false, rc, f)
|
2016-03-09 00:27:13 +00:00
|
|
|
})
|
|
|
|
})
|
2016-06-13 07:45:30 +00:00
|
|
|
|
2016-03-03 10:53:54 +00:00
|
|
|
// These tests take ~20 minutes each.
|
2017-08-01 12:06:11 +00:00
|
|
|
SIGDescribe("[Serial] [Slow] ReplicationController", func() {
|
2015-11-12 22:30:06 +00:00
|
|
|
// CPU tests via replication controllers
|
2016-06-13 07:45:30 +00:00
|
|
|
It(titleUp+" and verify decision stability", func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleUp("rc", common.KindRC, true, rc, f)
|
2015-11-12 22:30:06 +00:00
|
|
|
})
|
2016-06-13 07:45:30 +00:00
|
|
|
It(titleDown+" and verify decision stability", func() {
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleDown("rc", common.KindRC, true, rc, f)
|
2015-11-12 22:30:06 +00:00
|
|
|
})
|
2015-09-30 07:33:05 +00:00
|
|
|
})
|
2016-03-03 10:53:54 +00:00
|
|
|
|
2018-02-06 14:46:18 +00:00
|
|
|
SIGDescribe("ReplicationController light", func() {
|
2016-03-03 10:53:54 +00:00
|
|
|
It("Should scale from 1 pod to 2 pods", func() {
|
|
|
|
scaleTest := &HPAScaleTest{
|
|
|
|
initPods: 1,
|
|
|
|
totalInitialCPUUsage: 150,
|
|
|
|
perPodCPURequest: 200,
|
|
|
|
targetCPUUtilizationPercent: 50,
|
|
|
|
minPods: 1,
|
|
|
|
maxPods: 2,
|
|
|
|
firstScale: 2,
|
|
|
|
}
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleTest.run("rc-light", common.KindRC, rc, f)
|
2016-03-03 10:53:54 +00:00
|
|
|
})
|
2016-05-05 10:27:24 +00:00
|
|
|
It("Should scale from 2 pods to 1 pod", func() {
|
2016-03-03 10:53:54 +00:00
|
|
|
scaleTest := &HPAScaleTest{
|
|
|
|
initPods: 2,
|
|
|
|
totalInitialCPUUsage: 50,
|
|
|
|
perPodCPURequest: 200,
|
|
|
|
targetCPUUtilizationPercent: 50,
|
|
|
|
minPods: 1,
|
|
|
|
maxPods: 2,
|
|
|
|
firstScale: 1,
|
|
|
|
}
|
2017-02-15 14:37:36 +00:00
|
|
|
scaleTest.run("rc-light", common.KindRC, rc, f)
|
2016-03-03 10:53:54 +00:00
|
|
|
})
|
|
|
|
})
|
2015-09-07 10:26:23 +00:00
|
|
|
})
|
|
|
|
|
2015-12-02 22:51:34 +00:00
|
|
|
// HPAScaleTest struct is used by the scale(...) function.
|
|
|
|
type HPAScaleTest struct {
|
2018-10-19 12:59:24 +00:00
|
|
|
initPods int
|
|
|
|
totalInitialCPUUsage int
|
2016-03-03 10:53:54 +00:00
|
|
|
perPodCPURequest int64
|
2016-04-27 04:35:14 +00:00
|
|
|
targetCPUUtilizationPercent int32
|
|
|
|
minPods int32
|
|
|
|
maxPods int32
|
2018-10-30 16:50:54 +00:00
|
|
|
firstScale int
|
2016-03-03 10:53:54 +00:00
|
|
|
firstScaleStasis time.Duration
|
|
|
|
cpuBurst int
|
2016-04-27 04:35:14 +00:00
|
|
|
secondScale int32
|
2016-03-03 10:53:54 +00:00
|
|
|
secondScaleStasis time.Duration
|
2015-12-02 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// run is a method which runs an HPA lifecycle, from a starting state, to an expected
|
|
|
|
// The initial state is defined by the initPods parameter.
|
|
|
|
// The first state change is due to the CPU being consumed initially, which HPA responds to by changing pod counts.
|
2016-03-03 10:53:54 +00:00
|
|
|
// The second state change (optional) is due to the CPU burst parameter, which HPA again responds to.
|
2015-12-02 22:51:34 +00:00
|
|
|
// TODO The use of 3 states is arbitrary, we could eventually make this test handle "n" states once this test stabilizes.
|
2017-10-25 21:08:52 +00:00
|
|
|
func (scaleTest *HPAScaleTest) run(name string, kind schema.GroupVersionKind, rc *common.ResourceConsumer, f *framework.Framework) {
|
2017-06-10 08:47:31 +00:00
|
|
|
const timeToWait = 15 * time.Minute
|
2018-10-19 12:59:24 +00:00
|
|
|
rc = common.NewDynamicResourceConsumer(name, f.Namespace.Name, kind, scaleTest.initPods, scaleTest.totalInitialCPUUsage, 0, 0, scaleTest.perPodCPURequest, 200, f.ClientSet, f.InternalClientset, f.ScalesGetter)
|
2015-10-30 13:48:32 +00:00
|
|
|
defer rc.CleanUp()
|
2017-06-02 12:47:52 +00:00
|
|
|
hpa := common.CreateCPUHorizontalPodAutoscaler(rc, scaleTest.targetCPUUtilizationPercent, scaleTest.minPods, scaleTest.maxPods)
|
|
|
|
defer common.DeleteHorizontalPodAutoscaler(rc, hpa.Name)
|
2018-11-05 10:32:41 +00:00
|
|
|
|
2018-10-30 16:50:54 +00:00
|
|
|
rc.WaitForReplicas(scaleTest.firstScale, timeToWait)
|
2016-03-03 10:53:54 +00:00
|
|
|
if scaleTest.firstScaleStasis > 0 {
|
2018-11-05 10:32:41 +00:00
|
|
|
rc.EnsureDesiredReplicasInRange(scaleTest.firstScale, scaleTest.firstScale+1, scaleTest.firstScaleStasis, hpa.Name)
|
2016-03-03 10:53:54 +00:00
|
|
|
}
|
|
|
|
if scaleTest.cpuBurst > 0 && scaleTest.secondScale > 0 {
|
|
|
|
rc.ConsumeCPU(scaleTest.cpuBurst)
|
2017-06-10 08:47:31 +00:00
|
|
|
rc.WaitForReplicas(int(scaleTest.secondScale), timeToWait)
|
2016-03-03 10:53:54 +00:00
|
|
|
}
|
2015-12-02 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 21:08:52 +00:00
|
|
|
func scaleUp(name string, kind schema.GroupVersionKind, checkStability bool, rc *common.ResourceConsumer, f *framework.Framework) {
|
2016-06-13 07:45:30 +00:00
|
|
|
stasis := 0 * time.Minute
|
|
|
|
if checkStability {
|
|
|
|
stasis = 10 * time.Minute
|
|
|
|
}
|
2015-12-02 22:51:34 +00:00
|
|
|
scaleTest := &HPAScaleTest{
|
2016-03-03 10:53:54 +00:00
|
|
|
initPods: 1,
|
2018-10-25 09:16:31 +00:00
|
|
|
totalInitialCPUUsage: 250,
|
|
|
|
perPodCPURequest: 500,
|
2016-03-03 10:53:54 +00:00
|
|
|
targetCPUUtilizationPercent: 20,
|
|
|
|
minPods: 1,
|
|
|
|
maxPods: 5,
|
|
|
|
firstScale: 3,
|
2016-06-13 07:45:30 +00:00
|
|
|
firstScaleStasis: stasis,
|
2018-10-25 09:16:31 +00:00
|
|
|
cpuBurst: 700,
|
2016-03-03 10:53:54 +00:00
|
|
|
secondScale: 5,
|
2015-12-02 22:51:34 +00:00
|
|
|
}
|
|
|
|
scaleTest.run(name, kind, rc, f)
|
2015-10-30 13:48:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 21:08:52 +00:00
|
|
|
func scaleDown(name string, kind schema.GroupVersionKind, checkStability bool, rc *common.ResourceConsumer, f *framework.Framework) {
|
2016-06-13 07:45:30 +00:00
|
|
|
stasis := 0 * time.Minute
|
|
|
|
if checkStability {
|
|
|
|
stasis = 10 * time.Minute
|
|
|
|
}
|
2015-12-02 22:51:34 +00:00
|
|
|
scaleTest := &HPAScaleTest{
|
2016-03-03 10:53:54 +00:00
|
|
|
initPods: 5,
|
2018-10-25 09:16:31 +00:00
|
|
|
totalInitialCPUUsage: 325,
|
|
|
|
perPodCPURequest: 500,
|
2016-03-03 10:53:54 +00:00
|
|
|
targetCPUUtilizationPercent: 30,
|
|
|
|
minPods: 1,
|
|
|
|
maxPods: 5,
|
|
|
|
firstScale: 3,
|
2016-06-13 07:45:30 +00:00
|
|
|
firstScaleStasis: stasis,
|
2016-06-15 09:33:50 +00:00
|
|
|
cpuBurst: 10,
|
2016-03-03 10:53:54 +00:00
|
|
|
secondScale: 1,
|
2015-12-02 22:51:34 +00:00
|
|
|
}
|
|
|
|
scaleTest.run(name, kind, rc, f)
|
2015-10-30 13:48:32 +00:00
|
|
|
}
|