mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
HPA: parameterize stasis, minReplicas, maxReplicas as struct.
This commit is contained in:
parent
2fcf157512
commit
98153fcedc
@ -26,10 +26,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kindRC = "replicationController"
|
kindRC = "replicationController"
|
||||||
kindDeployment = "deployment"
|
kindDeployment = "deployment"
|
||||||
subresource = "scale"
|
subresource = "scale"
|
||||||
stabilityTimeout = 10 * time.Minute
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Horizontal pod autoscaling (scale resource: CPU) [Skipped]", func() {
|
var _ = Describe("Horizontal pod autoscaling (scale resource: CPU) [Skipped]", func() {
|
||||||
@ -60,28 +59,69 @@ var _ = Describe("Horizontal pod autoscaling (scale resource: CPU) [Skipped]", f
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func scaleUp(name, kind string, rc *ResourceConsumer, f *Framework) {
|
// HPAScaleTest struct is used by the scale(...) function.
|
||||||
rc = NewDynamicResourceConsumer(name, kind, 1, 250, 0, 500, 100, f)
|
type HPAScaleTest struct {
|
||||||
|
initPods int
|
||||||
|
cpuStart int
|
||||||
|
maxCPU int64
|
||||||
|
idealCPU int
|
||||||
|
minPods int
|
||||||
|
maxPods int
|
||||||
|
firstScale int
|
||||||
|
firstScaleStasis time.Duration
|
||||||
|
cpuBurst int
|
||||||
|
secondScale int
|
||||||
|
secondScaleStasis time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// The second state change is due to the CPU burst parameter, which HPA again responds to.
|
||||||
|
// TODO The use of 3 states is arbitrary, we could eventually make this test handle "n" states once this test stabilizes.
|
||||||
|
func (scaleTest *HPAScaleTest) run(name, kind string, rc *ResourceConsumer, f *Framework) {
|
||||||
|
rc = NewDynamicResourceConsumer(name, kind, scaleTest.initPods, scaleTest.cpuStart, 0, scaleTest.maxCPU, 100, f)
|
||||||
defer rc.CleanUp()
|
defer rc.CleanUp()
|
||||||
createCPUHorizontalPodAutoscaler(rc, 20)
|
createCPUHorizontalPodAutoscaler(rc, scaleTest.idealCPU, scaleTest.minPods, scaleTest.maxPods)
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(scaleTest.firstScale)
|
||||||
rc.EnsureDesiredReplicas(3, stabilityTimeout)
|
rc.EnsureDesiredReplicas(scaleTest.firstScale, scaleTest.firstScaleStasis)
|
||||||
rc.ConsumeCPU(700)
|
rc.ConsumeCPU(scaleTest.cpuBurst)
|
||||||
rc.WaitForReplicas(5)
|
rc.WaitForReplicas(scaleTest.secondScale)
|
||||||
|
}
|
||||||
|
|
||||||
|
func scaleUp(name, kind string, rc *ResourceConsumer, f *Framework) {
|
||||||
|
scaleTest := &HPAScaleTest{
|
||||||
|
initPods: 1,
|
||||||
|
cpuStart: 250,
|
||||||
|
maxCPU: 500,
|
||||||
|
idealCPU: .2 * 100,
|
||||||
|
minPods: 1,
|
||||||
|
maxPods: 5,
|
||||||
|
firstScale: 3,
|
||||||
|
firstScaleStasis: 10 * time.Minute,
|
||||||
|
cpuBurst: 700,
|
||||||
|
secondScale: 5,
|
||||||
|
}
|
||||||
|
scaleTest.run(name, kind, rc, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func scaleDown(name, kind string, rc *ResourceConsumer, f *Framework) {
|
func scaleDown(name, kind string, rc *ResourceConsumer, f *Framework) {
|
||||||
rc = NewDynamicResourceConsumer(name, kind, 5, 400, 0, 500, 100, f)
|
scaleTest := &HPAScaleTest{
|
||||||
defer rc.CleanUp()
|
initPods: 5,
|
||||||
createCPUHorizontalPodAutoscaler(rc, 30)
|
cpuStart: 400,
|
||||||
rc.WaitForReplicas(3)
|
maxCPU: 500,
|
||||||
rc.EnsureDesiredReplicas(3, stabilityTimeout)
|
idealCPU: .3 * 100,
|
||||||
rc.ConsumeCPU(100)
|
minPods: 1,
|
||||||
rc.WaitForReplicas(1)
|
maxPods: 5,
|
||||||
|
firstScale: 3,
|
||||||
|
firstScaleStasis: 10 * time.Minute,
|
||||||
|
cpuBurst: 100,
|
||||||
|
secondScale: 1,
|
||||||
|
}
|
||||||
|
scaleTest.run(name, kind, rc, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu int) {
|
func createCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu, minReplicas, maxRepl int) {
|
||||||
minReplicas := 1
|
|
||||||
hpa := &extensions.HorizontalPodAutoscaler{
|
hpa := &extensions.HorizontalPodAutoscaler{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: rc.name,
|
Name: rc.name,
|
||||||
@ -94,7 +134,7 @@ func createCPUHorizontalPodAutoscaler(rc *ResourceConsumer, cpu int) {
|
|||||||
Subresource: subresource,
|
Subresource: subresource,
|
||||||
},
|
},
|
||||||
MinReplicas: &minReplicas,
|
MinReplicas: &minReplicas,
|
||||||
MaxReplicas: 5,
|
MaxReplicas: maxRepl,
|
||||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: cpu},
|
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: cpu},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user