mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #21750 from piosz/hpa-status-current-utilization
Auto commit by PR queue bot
This commit is contained in:
commit
ff758bec58
@ -62,6 +62,8 @@ type testCase struct {
|
||||
desiredReplicas int
|
||||
// CPU target utilization as a percentage of the requested resources.
|
||||
CPUTarget int
|
||||
CPUCurrent int
|
||||
verifyCPUCurrent bool
|
||||
reportedLevels []uint64
|
||||
reportedCPURequests []resource.Quantity
|
||||
cmTarget *extensions.CustomMetricTargetList
|
||||
@ -71,6 +73,21 @@ type testCase struct {
|
||||
verifyEvents bool
|
||||
}
|
||||
|
||||
func (tc *testCase) computeCPUCurrent() {
|
||||
if len(tc.reportedLevels) != len(tc.reportedCPURequests) || len(tc.reportedLevels) == 0 {
|
||||
return
|
||||
}
|
||||
reported := 0
|
||||
for _, r := range tc.reportedLevels {
|
||||
reported += int(r)
|
||||
}
|
||||
requested := 0
|
||||
for _, req := range tc.reportedCPURequests {
|
||||
requested += int(req.MilliValue())
|
||||
}
|
||||
tc.CPUCurrent = 100 * reported / requested
|
||||
}
|
||||
|
||||
func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
|
||||
namespace := "test-namespace"
|
||||
hpaName := "test-hpa"
|
||||
@ -80,6 +97,7 @@ func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
|
||||
tc.scaleUpdated = false
|
||||
tc.statusUpdated = false
|
||||
tc.eventCreated = false
|
||||
tc.computeCPUCurrent()
|
||||
|
||||
fakeClient := &fake.Clientset{}
|
||||
fakeClient.AddReactor("list", "horizontalpodautoscalers", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||
@ -198,6 +216,10 @@ func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
|
||||
assert.Equal(t, hpaName, obj.Name)
|
||||
assert.Equal(t, tc.desiredReplicas, obj.Status.DesiredReplicas)
|
||||
tc.statusUpdated = true
|
||||
if tc.verifyCPUCurrent {
|
||||
assert.NotNil(t, obj.Status.CurrentCPUUtilizationPercentage)
|
||||
assert.Equal(t, tc.CPUCurrent, *obj.Status.CurrentCPUUtilizationPercentage)
|
||||
}
|
||||
return true, obj, nil
|
||||
})
|
||||
|
||||
@ -242,6 +264,7 @@ func TestScaleUp(t *testing.T) {
|
||||
initialReplicas: 3,
|
||||
desiredReplicas: 5,
|
||||
CPUTarget: 30,
|
||||
verifyCPUCurrent: true,
|
||||
reportedLevels: []uint64{300, 500, 700},
|
||||
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
||||
}
|
||||
@ -274,6 +297,7 @@ func TestScaleDown(t *testing.T) {
|
||||
initialReplicas: 5,
|
||||
desiredReplicas: 3,
|
||||
CPUTarget: 50,
|
||||
verifyCPUCurrent: true,
|
||||
reportedLevels: []uint64{100, 300, 500, 250, 250},
|
||||
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
||||
}
|
||||
@ -354,7 +378,7 @@ func TestZeroReplicas(t *testing.T) {
|
||||
tc.runTest(t)
|
||||
}
|
||||
|
||||
func TestToFewReplicas(t *testing.T) {
|
||||
func TestTooFewReplicas(t *testing.T) {
|
||||
tc := testCase{
|
||||
minReplicas: 3,
|
||||
maxReplicas: 5,
|
||||
|
Loading…
Reference in New Issue
Block a user