mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +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
|
desiredReplicas int
|
||||||
// CPU target utilization as a percentage of the requested resources.
|
// CPU target utilization as a percentage of the requested resources.
|
||||||
CPUTarget int
|
CPUTarget int
|
||||||
|
CPUCurrent int
|
||||||
|
verifyCPUCurrent bool
|
||||||
reportedLevels []uint64
|
reportedLevels []uint64
|
||||||
reportedCPURequests []resource.Quantity
|
reportedCPURequests []resource.Quantity
|
||||||
cmTarget *extensions.CustomMetricTargetList
|
cmTarget *extensions.CustomMetricTargetList
|
||||||
@ -71,6 +73,21 @@ type testCase struct {
|
|||||||
verifyEvents bool
|
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 {
|
func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
|
||||||
namespace := "test-namespace"
|
namespace := "test-namespace"
|
||||||
hpaName := "test-hpa"
|
hpaName := "test-hpa"
|
||||||
@ -80,6 +97,7 @@ func (tc *testCase) prepareTestClient(t *testing.T) *fake.Clientset {
|
|||||||
tc.scaleUpdated = false
|
tc.scaleUpdated = false
|
||||||
tc.statusUpdated = false
|
tc.statusUpdated = false
|
||||||
tc.eventCreated = false
|
tc.eventCreated = false
|
||||||
|
tc.computeCPUCurrent()
|
||||||
|
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
fakeClient.AddReactor("list", "horizontalpodautoscalers", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
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, hpaName, obj.Name)
|
||||||
assert.Equal(t, tc.desiredReplicas, obj.Status.DesiredReplicas)
|
assert.Equal(t, tc.desiredReplicas, obj.Status.DesiredReplicas)
|
||||||
tc.statusUpdated = true
|
tc.statusUpdated = true
|
||||||
|
if tc.verifyCPUCurrent {
|
||||||
|
assert.NotNil(t, obj.Status.CurrentCPUUtilizationPercentage)
|
||||||
|
assert.Equal(t, tc.CPUCurrent, *obj.Status.CurrentCPUUtilizationPercentage)
|
||||||
|
}
|
||||||
return true, obj, nil
|
return true, obj, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -242,6 +264,7 @@ func TestScaleUp(t *testing.T) {
|
|||||||
initialReplicas: 3,
|
initialReplicas: 3,
|
||||||
desiredReplicas: 5,
|
desiredReplicas: 5,
|
||||||
CPUTarget: 30,
|
CPUTarget: 30,
|
||||||
|
verifyCPUCurrent: true,
|
||||||
reportedLevels: []uint64{300, 500, 700},
|
reportedLevels: []uint64{300, 500, 700},
|
||||||
reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
|
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,
|
initialReplicas: 5,
|
||||||
desiredReplicas: 3,
|
desiredReplicas: 3,
|
||||||
CPUTarget: 50,
|
CPUTarget: 50,
|
||||||
|
verifyCPUCurrent: true,
|
||||||
reportedLevels: []uint64{100, 300, 500, 250, 250},
|
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")},
|
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)
|
tc.runTest(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToFewReplicas(t *testing.T) {
|
func TestTooFewReplicas(t *testing.T) {
|
||||||
tc := testCase{
|
tc := testCase{
|
||||||
minReplicas: 3,
|
minReplicas: 3,
|
||||||
maxReplicas: 5,
|
maxReplicas: 5,
|
||||||
|
Loading…
Reference in New Issue
Block a user