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
f843aff0
Commit
f843aff0
authored
Nov 10, 2016
by
Jerzy Szczepkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More unittests for HPA.
Added more unittests for HPA. Fixed inconsistency in replica calculator when usageRatio == 1.0.
parent
a7870447
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
3 deletions
+102
-3
metrics_client.go
pkg/controller/podautoscaler/metrics/metrics_client.go
+2
-2
replica_calculator.go
pkg/controller/podautoscaler/replica_calculator.go
+1
-1
replica_calculator_test.go
pkg/controller/podautoscaler/replica_calculator_test.go
+99
-0
No files found.
pkg/controller/podautoscaler/metrics/metrics_client.go
View file @
f843aff0
...
...
@@ -88,7 +88,7 @@ func (h *HeapsterMetricsClient) GetResourceMetric(resource api.ResourceName, nam
ProxyGet
(
h
.
heapsterScheme
,
h
.
heapsterService
,
h
.
heapsterPort
,
metricPath
,
params
)
.
DoRaw
()
if
err
!=
nil
{
return
nil
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get
pod resource metrics
: %v"
,
err
)
return
nil
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get
heapster service
: %v"
,
err
)
}
glog
.
V
(
4
)
.
Infof
(
"Heapster metrics result: %s"
,
string
(
resultRaw
))
...
...
@@ -158,7 +158,7 @@ func (h *HeapsterMetricsClient) GetRawMetric(metricName string, namespace string
ProxyGet
(
h
.
heapsterScheme
,
h
.
heapsterService
,
h
.
heapsterPort
,
metricPath
,
map
[
string
]
string
{
"start"
:
startTime
.
Format
(
time
.
RFC3339
)})
.
DoRaw
()
if
err
!=
nil
{
return
nil
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get
pod metrics
: %v"
,
err
)
return
nil
,
time
.
Time
{},
fmt
.
Errorf
(
"failed to get
heapster service
: %v"
,
err
)
}
var
metrics
heapster
.
MetricResultList
...
...
pkg/controller/podautoscaler/replica_calculator.go
View file @
f843aff0
...
...
@@ -116,7 +116,7 @@ func (c *ReplicaCalculator) GetResourceReplicas(currentReplicas int32, targetUti
for
podName
:=
range
missingPods
{
metrics
[
podName
]
=
requests
[
podName
]
}
}
else
{
}
else
if
usageRatio
>
1.0
{
// on a scale-up, treat missing pods as using 0% of the resource request
for
podName
:=
range
missingPods
{
metrics
[
podName
]
=
0
...
...
pkg/controller/podautoscaler/replica_calculator_test.go
View file @
f843aff0
...
...
@@ -482,6 +482,105 @@ func TestReplicaCalcEmptyCPURequest(t *testing.T) {
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsNoChangeEq
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
2
,
expectedReplicas
:
2
,
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
1000
},
targetUtilization
:
100
,
expectedUtilization
:
100
,
},
}
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsNoChangeGt
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
2
,
expectedReplicas
:
2
,
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
1900
},
targetUtilization
:
100
,
expectedUtilization
:
190
,
},
}
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsNoChangeLt
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
2
,
expectedReplicas
:
2
,
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
600
},
targetUtilization
:
100
,
expectedUtilization
:
60
,
},
}
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsUnreadyNoChange
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
3
,
expectedReplicas
:
3
,
podReadiness
:
[]
api
.
ConditionStatus
{
api
.
ConditionFalse
,
api
.
ConditionTrue
,
api
.
ConditionTrue
},
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
100
,
450
},
targetUtilization
:
50
,
expectedUtilization
:
45
,
},
}
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsUnreadyScaleUp
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
3
,
expectedReplicas
:
4
,
podReadiness
:
[]
api
.
ConditionStatus
{
api
.
ConditionFalse
,
api
.
ConditionTrue
,
api
.
ConditionTrue
},
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
100
,
2000
},
targetUtilization
:
50
,
expectedUtilization
:
200
,
},
}
tc
.
runTest
(
t
)
}
func
TestReplicaCalcMissingMetricsUnreadyScaleDown
(
t
*
testing
.
T
)
{
tc
:=
replicaCalcTestCase
{
currentReplicas
:
4
,
expectedReplicas
:
3
,
podReadiness
:
[]
api
.
ConditionStatus
{
api
.
ConditionFalse
,
api
.
ConditionTrue
,
api
.
ConditionTrue
,
api
.
ConditionTrue
},
resource
:
&
resourceInfo
{
name
:
api
.
ResourceCPU
,
requests
:
[]
resource
.
Quantity
{
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
),
resource
.
MustParse
(
"1.0"
)},
levels
:
[]
int64
{
100
,
100
,
100
},
targetUtilization
:
50
,
expectedUtilization
:
10
,
},
}
tc
.
runTest
(
t
)
}
// TestComputedToleranceAlgImplementation is a regression test which
// back-calculates a minimal percentage for downscaling based on a small percentage
// increase in pod utilization which is calibrated against the tolerance value.
...
...
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