mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Merge pull request #14167 from socaa/static-consumption
Auto commit by PR queue bot
This commit is contained in:
commit
979bfc0f18
@ -28,15 +28,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
consumptionTimeInSeconds = 30
|
dynamicConsumptionTimeInSeconds = 30
|
||||||
sleepTime = 30 * time.Second
|
staticConsumptionTimeInSeconds = 3600
|
||||||
requestSizeInMillicores = 100
|
dynamicRequestSizeInMillicores = 100
|
||||||
requestSizeInMegabytes = 100
|
dynamicRequestSizeInMegabytes = 100
|
||||||
port = 80
|
port = 80
|
||||||
targetPort = 8080
|
targetPort = 8080
|
||||||
timeoutRC = 120 * time.Second
|
timeoutRC = 120 * time.Second
|
||||||
image = "gcr.io/google_containers/resource_consumer:beta"
|
image = "gcr.io/google_containers/resource_consumer:beta"
|
||||||
rcIsNil = "ERROR: replicationController = nil"
|
rcIsNil = "ERROR: replicationController = nil"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -48,12 +48,24 @@ rc.ConsumeCPU(300)
|
|||||||
// ... check your assumption here
|
// ... check your assumption here
|
||||||
*/
|
*/
|
||||||
type ResourceConsumer struct {
|
type ResourceConsumer struct {
|
||||||
name string
|
name string
|
||||||
framework *Framework
|
framework *Framework
|
||||||
cpu chan int
|
cpu chan int
|
||||||
mem chan int
|
mem chan int
|
||||||
stopCPU chan int
|
stopCPU chan int
|
||||||
stopMem chan int
|
stopMem chan int
|
||||||
|
consumptionTimeInSeconds int
|
||||||
|
sleepTime time.Duration
|
||||||
|
requestSizeInMillicores int
|
||||||
|
requestSizeInMegabytes int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDynamicResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||||
|
return newResourceConsumer(name, replicas, initCPU, initMemory, dynamicConsumptionTimeInSeconds, dynamicRequestSizeInMillicores, dynamicRequestSizeInMegabytes, cpuLimit, memLimit, framework)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStaticResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||||
|
return newResourceConsumer(name, replicas, initCPU, initMemory, staticConsumptionTimeInSeconds, initCPU/replicas, initMemory/replicas, cpuLimit, memLimit, framework)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,15 +75,19 @@ initMemory argument is in megabytes
|
|||||||
memLimit argument is in megabytes, memLimit is a maximum amount of memory that can be consumed by a single pod
|
memLimit argument is in megabytes, memLimit is a maximum amount of memory that can be consumed by a single pod
|
||||||
cpuLimit argument is in millicores, cpuLimit is a maximum amount of cpu that can be consumed by a single pod
|
cpuLimit argument is in millicores, cpuLimit is a maximum amount of cpu that can be consumed by a single pod
|
||||||
*/
|
*/
|
||||||
func NewResourceConsumer(name string, replicas, initCPU, initMemory int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
func newResourceConsumer(name string, replicas, initCPU, initMemory, consumptionTimeInSeconds, requestSizeInMillicores, requestSizeInMegabytes int, cpuLimit, memLimit int64, framework *Framework) *ResourceConsumer {
|
||||||
runServiceAndRCForResourceConsumer(framework.Client, framework.Namespace.Name, name, replicas, cpuLimit, memLimit)
|
runServiceAndRCForResourceConsumer(framework.Client, framework.Namespace.Name, name, replicas, cpuLimit, memLimit)
|
||||||
rc := &ResourceConsumer{
|
rc := &ResourceConsumer{
|
||||||
name: name,
|
name: name,
|
||||||
framework: framework,
|
framework: framework,
|
||||||
cpu: make(chan int),
|
cpu: make(chan int),
|
||||||
mem: make(chan int),
|
mem: make(chan int),
|
||||||
stopCPU: make(chan int),
|
stopCPU: make(chan int),
|
||||||
stopMem: make(chan int),
|
stopMem: make(chan int),
|
||||||
|
consumptionTimeInSeconds: consumptionTimeInSeconds,
|
||||||
|
sleepTime: time.Duration(consumptionTimeInSeconds) * time.Second,
|
||||||
|
requestSizeInMillicores: requestSizeInMillicores,
|
||||||
|
requestSizeInMegabytes: requestSizeInMegabytes,
|
||||||
}
|
}
|
||||||
go rc.makeConsumeCPURequests()
|
go rc.makeConsumeCPURequests()
|
||||||
rc.ConsumeCPU(initCPU)
|
rc.ConsumeCPU(initCPU)
|
||||||
@ -93,18 +109,22 @@ func (rc *ResourceConsumer) ConsumeMem(megabytes int) {
|
|||||||
func (rc *ResourceConsumer) makeConsumeCPURequests() {
|
func (rc *ResourceConsumer) makeConsumeCPURequests() {
|
||||||
var count int
|
var count int
|
||||||
var rest int
|
var rest int
|
||||||
|
sleepTime := time.Duration(0)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case millicores := <-rc.cpu:
|
case millicores := <-rc.cpu:
|
||||||
count = millicores / requestSizeInMillicores
|
if rc.requestSizeInMillicores != 0 {
|
||||||
rest = millicores - count*requestSizeInMillicores
|
count = millicores / rc.requestSizeInMillicores
|
||||||
|
}
|
||||||
|
rest = millicores - count*rc.requestSizeInMillicores
|
||||||
case <-time.After(sleepTime):
|
case <-time.After(sleepTime):
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
rc.sendConsumeCPURequests(count, requestSizeInMillicores, consumptionTimeInSeconds)
|
rc.sendConsumeCPURequests(count, rc.requestSizeInMillicores, rc.consumptionTimeInSeconds)
|
||||||
}
|
}
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
go rc.sendOneConsumeCPURequest(rest, consumptionTimeInSeconds)
|
go rc.sendOneConsumeCPURequest(rest, rc.consumptionTimeInSeconds)
|
||||||
}
|
}
|
||||||
|
sleepTime = rc.sleepTime
|
||||||
case <-rc.stopCPU:
|
case <-rc.stopCPU:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -114,18 +134,22 @@ func (rc *ResourceConsumer) makeConsumeCPURequests() {
|
|||||||
func (rc *ResourceConsumer) makeConsumeMemRequests() {
|
func (rc *ResourceConsumer) makeConsumeMemRequests() {
|
||||||
var count int
|
var count int
|
||||||
var rest int
|
var rest int
|
||||||
|
sleepTime := time.Duration(0)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case megabytes := <-rc.mem:
|
case megabytes := <-rc.mem:
|
||||||
count = megabytes / requestSizeInMegabytes
|
if rc.requestSizeInMegabytes != 0 {
|
||||||
rest = megabytes - count*requestSizeInMegabytes
|
count = megabytes / rc.requestSizeInMegabytes
|
||||||
|
}
|
||||||
|
rest = megabytes - count*rc.requestSizeInMegabytes
|
||||||
case <-time.After(sleepTime):
|
case <-time.After(sleepTime):
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
rc.sendConsumeMemRequests(count, requestSizeInMegabytes, consumptionTimeInSeconds)
|
rc.sendConsumeMemRequests(count, rc.requestSizeInMegabytes, rc.consumptionTimeInSeconds)
|
||||||
}
|
}
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
go rc.sendOneConsumeMemRequest(rest, consumptionTimeInSeconds)
|
go rc.sendOneConsumeMemRequest(rest, rc.consumptionTimeInSeconds)
|
||||||
}
|
}
|
||||||
|
sleepTime = rc.sleepTime
|
||||||
case <-rc.stopMem:
|
case <-rc.stopMem:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -42,28 +42,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
|
|
||||||
// CPU tests
|
// CPU tests
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.7")
|
createCPUHorizontalPodAutoscaler(rc, "0.7")
|
||||||
rc.WaitForReplicas(1)
|
rc.WaitForReplicas(1)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
||||||
rc.WaitForReplicas(5)
|
rc.WaitForReplicas(5)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 700, 0, 800, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeCPU(300)
|
rc.ConsumeCPU(300)
|
||||||
@ -72,7 +72,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 300, 0, 400, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 300, 0, 400, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
createCPUHorizontalPodAutoscaler(rc, "0.1")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeCPU(700)
|
rc.ConsumeCPU(700)
|
||||||
@ -81,7 +81,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 3, 0, 0, 800, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 800, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||||
rc.WaitForReplicas(1)
|
rc.WaitForReplicas(1)
|
||||||
rc.ConsumeCPU(700)
|
rc.ConsumeCPU(700)
|
||||||
@ -90,7 +90,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: CPU)", func() {
|
||||||
rc = NewResourceConsumer("rc", 5, 700, 0, 200, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 5, 700, 0, 200, 100, f)
|
||||||
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
createCPUHorizontalPodAutoscaler(rc, "0.3")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeCPU(100)
|
rc.ConsumeCPU(100)
|
||||||
@ -100,28 +100,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
|
|
||||||
// Memory tests
|
// Memory tests
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 0, 800, 100, 900, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 0, 800, 100, 900, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 100, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "700")
|
createMemoryHorizontalPodAutoscaler(rc, "700")
|
||||||
rc.WaitForReplicas(1)
|
rc.WaitForReplicas(1)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to maximum 5 pods (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "100")
|
createMemoryHorizontalPodAutoscaler(rc, "100")
|
||||||
rc.WaitForReplicas(5)
|
rc.WaitForReplicas(5)
|
||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 0, 700, 100, 800, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeMem(100)
|
rc.ConsumeMem(100)
|
||||||
@ -130,7 +130,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 1 pod to 3 pods and from 3 to 5 (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 1, 0, 500, 100, 1100, f)
|
rc = NewDynamicResourceConsumer("rc", 1, 0, 500, 100, 1100, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "200")
|
createMemoryHorizontalPodAutoscaler(rc, "200")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeMem(1000)
|
rc.ConsumeMem(1000)
|
||||||
@ -139,7 +139,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 3 pods to 1 pod and from 1 to 3 (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 3, 0, 0, 100, 800, f)
|
rc = NewDynamicResourceConsumer("rc", 3, 0, 0, 100, 800, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||||
rc.WaitForReplicas(1)
|
rc.WaitForReplicas(1)
|
||||||
rc.ConsumeMem(700)
|
rc.ConsumeMem(700)
|
||||||
@ -147,7 +147,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
|
|||||||
rc.CleanUp()
|
rc.CleanUp()
|
||||||
})
|
})
|
||||||
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
It("[Skipped][Horizontal pod autoscaling Suite] should scale from 5 pods to 3 pods and from 3 to 1 (scale resource: Memory)", func() {
|
||||||
rc = NewResourceConsumer("rc", 5, 0, 700, 100, 800, f)
|
rc = NewDynamicResourceConsumer("rc", 5, 0, 700, 100, 800, f)
|
||||||
createMemoryHorizontalPodAutoscaler(rc, "300")
|
createMemoryHorizontalPodAutoscaler(rc, "300")
|
||||||
rc.WaitForReplicas(3)
|
rc.WaitForReplicas(3)
|
||||||
rc.ConsumeMem(100)
|
rc.ConsumeMem(100)
|
||||||
|
Loading…
Reference in New Issue
Block a user