Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
979bfc0f
Commit
979bfc0f
authored
Sep 21, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14167 from socaa/static-consumption
Auto commit by PR queue bot
parents
1446b7c4
152991f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
44 deletions
+68
-44
autoscaling_utils.go
test/e2e/autoscaling_utils.go
+54
-30
horizontal_pod_autoscaling.go
test/e2e/horizontal_pod_autoscaling.go
+14
-14
No files found.
test/e2e/autoscaling_utils.go
View file @
979bfc0f
...
...
@@ -28,15 +28,15 @@ import (
)
const
(
c
onsumptionTimeInSeconds
=
30
s
leepTime
=
30
*
time
.
Second
r
equestSizeInMillicores
=
100
r
equestSizeInMegabytes
=
100
port
=
80
targetPort
=
8080
timeoutRC
=
120
*
time
.
Second
image
=
"gcr.io/google_containers/resource_consumer:beta"
rcIsNil
=
"ERROR: replicationController = nil"
dynamicC
onsumptionTimeInSeconds
=
30
s
taticConsumptionTimeInSeconds
=
3600
dynamicR
equestSizeInMillicores
=
100
dynamicR
equestSizeInMegabytes
=
100
port
=
80
targetPort
=
8080
timeoutRC
=
120
*
time
.
Second
image
=
"gcr.io/google_containers/resource_consumer:beta"
rcIsNil
=
"ERROR: replicationController = nil"
)
/*
...
...
@@ -48,12 +48,24 @@ rc.ConsumeCPU(300)
// ... check your assumption here
*/
type
ResourceConsumer
struct
{
name
string
framework
*
Framework
cpu
chan
int
mem
chan
int
stopCPU
chan
int
stopMem
chan
int
name
string
framework
*
Framework
cpu
chan
int
mem
chan
int
stopCPU
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
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
)
rc
:=
&
ResourceConsumer
{
name
:
name
,
framework
:
framework
,
cpu
:
make
(
chan
int
),
mem
:
make
(
chan
int
),
stopCPU
:
make
(
chan
int
),
stopMem
:
make
(
chan
int
),
name
:
name
,
framework
:
framework
,
cpu
:
make
(
chan
int
),
mem
:
make
(
chan
int
),
stopCPU
:
make
(
chan
int
),
stopMem
:
make
(
chan
int
),
consumptionTimeInSeconds
:
consumptionTimeInSeconds
,
sleepTime
:
time
.
Duration
(
consumptionTimeInSeconds
)
*
time
.
Second
,
requestSizeInMillicores
:
requestSizeInMillicores
,
requestSizeInMegabytes
:
requestSizeInMegabytes
,
}
go
rc
.
makeConsumeCPURequests
()
rc
.
ConsumeCPU
(
initCPU
)
...
...
@@ -93,18 +109,22 @@ func (rc *ResourceConsumer) ConsumeMem(megabytes int) {
func
(
rc
*
ResourceConsumer
)
makeConsumeCPURequests
()
{
var
count
int
var
rest
int
sleepTime
:=
time
.
Duration
(
0
)
for
{
select
{
case
millicores
:=
<-
rc
.
cpu
:
count
=
millicores
/
requestSizeInMillicores
rest
=
millicores
-
count
*
requestSizeInMillicores
if
rc
.
requestSizeInMillicores
!=
0
{
count
=
millicores
/
rc
.
requestSizeInMillicores
}
rest
=
millicores
-
count
*
rc
.
requestSizeInMillicores
case
<-
time
.
After
(
sleepTime
)
:
if
count
>
0
{
rc
.
sendConsumeCPURequests
(
count
,
r
equestSizeInMillicores
,
consumptionTimeInSeconds
)
rc
.
sendConsumeCPURequests
(
count
,
r
c
.
requestSizeInMillicores
,
rc
.
consumptionTimeInSeconds
)
}
if
rest
>
0
{
go
rc
.
sendOneConsumeCPURequest
(
rest
,
consumptionTimeInSeconds
)
go
rc
.
sendOneConsumeCPURequest
(
rest
,
rc
.
consumptionTimeInSeconds
)
}
sleepTime
=
rc
.
sleepTime
case
<-
rc
.
stopCPU
:
return
}
...
...
@@ -114,18 +134,22 @@ func (rc *ResourceConsumer) makeConsumeCPURequests() {
func
(
rc
*
ResourceConsumer
)
makeConsumeMemRequests
()
{
var
count
int
var
rest
int
sleepTime
:=
time
.
Duration
(
0
)
for
{
select
{
case
megabytes
:=
<-
rc
.
mem
:
count
=
megabytes
/
requestSizeInMegabytes
rest
=
megabytes
-
count
*
requestSizeInMegabytes
if
rc
.
requestSizeInMegabytes
!=
0
{
count
=
megabytes
/
rc
.
requestSizeInMegabytes
}
rest
=
megabytes
-
count
*
rc
.
requestSizeInMegabytes
case
<-
time
.
After
(
sleepTime
)
:
if
count
>
0
{
rc
.
sendConsumeMemRequests
(
count
,
r
equestSizeInMegabytes
,
consumptionTimeInSeconds
)
rc
.
sendConsumeMemRequests
(
count
,
r
c
.
requestSizeInMegabytes
,
rc
.
consumptionTimeInSeconds
)
}
if
rest
>
0
{
go
rc
.
sendOneConsumeMemRequest
(
rest
,
consumptionTimeInSeconds
)
go
rc
.
sendOneConsumeMemRequest
(
rest
,
rc
.
consumptionTimeInSeconds
)
}
sleepTime
=
rc
.
sleepTime
case
<-
rc
.
stopMem
:
return
}
...
...
test/e2e/horizontal_pod_autoscaling.go
View file @
979bfc0f
...
...
@@ -42,28 +42,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
// CPU tests
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
700
,
0
,
800
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.3"
)
rc
.
WaitForReplicas
(
3
)
rc
.
CleanUp
()
})
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
3
,
0
,
0
,
100
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.7"
)
rc
.
WaitForReplicas
(
1
)
rc
.
CleanUp
()
})
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
700
,
0
,
800
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.1"
)
rc
.
WaitForReplicas
(
5
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
1
,
700
,
0
,
800
,
100
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
700
,
0
,
800
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.3"
)
rc
.
WaitForReplicas
(
3
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
1
,
300
,
0
,
400
,
100
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
300
,
0
,
400
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.1"
)
rc
.
WaitForReplicas
(
3
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
3
,
0
,
0
,
800
,
100
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
3
,
0
,
0
,
800
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.3"
)
rc
.
WaitForReplicas
(
1
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
5
,
700
,
0
,
200
,
100
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
5
,
700
,
0
,
200
,
100
,
f
)
createCPUHorizontalPodAutoscaler
(
rc
,
"0.3"
)
rc
.
WaitForReplicas
(
3
)
rc
.
ConsumeCPU
(
100
)
...
...
@@ -100,28 +100,28 @@ var _ = Describe("Horizontal pod autoscaling", func() {
// Memory tests
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
0
,
800
,
100
,
900
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"300"
)
rc
.
WaitForReplicas
(
3
)
rc
.
CleanUp
()
})
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
3
,
0
,
0
,
100
,
100
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"700"
)
rc
.
WaitForReplicas
(
1
)
rc
.
CleanUp
()
})
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
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
0
,
700
,
100
,
800
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"100"
)
rc
.
WaitForReplicas
(
5
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
1
,
0
,
700
,
100
,
800
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
0
,
700
,
100
,
800
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"300"
)
rc
.
WaitForReplicas
(
3
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
1
,
0
,
500
,
100
,
1100
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
1
,
0
,
500
,
100
,
1100
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"200"
)
rc
.
WaitForReplicas
(
3
)
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
3
,
0
,
0
,
100
,
800
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
3
,
0
,
0
,
100
,
800
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"300"
)
rc
.
WaitForReplicas
(
1
)
rc
.
ConsumeMem
(
700
)
...
...
@@ -147,7 +147,7 @@ var _ = Describe("Horizontal pod autoscaling", func() {
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
()
{
rc
=
NewResourceConsumer
(
"rc"
,
5
,
0
,
700
,
100
,
800
,
f
)
rc
=
New
Dynamic
ResourceConsumer
(
"rc"
,
5
,
0
,
700
,
100
,
800
,
f
)
createMemoryHorizontalPodAutoscaler
(
rc
,
"300"
)
rc
.
WaitForReplicas
(
3
)
rc
.
ConsumeMem
(
100
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment