...
1
16
17 package autoscaling
18
19 import (
20 "context"
21 "fmt"
22 "time"
23
24 autoscalingv2 "k8s.io/api/autoscaling/v2"
25 "k8s.io/kubernetes/test/e2e/framework"
26 e2eautoscaling "k8s.io/kubernetes/test/e2e/framework/autoscaling"
27 "k8s.io/kubernetes/test/e2e/upgrades"
28
29 "github.com/onsi/ginkgo/v2"
30 )
31
32
33 type HPAUpgradeTest struct {
34 rc *e2eautoscaling.ResourceConsumer
35 hpa *autoscalingv2.HorizontalPodAutoscaler
36 }
37
38
39 func (HPAUpgradeTest) Name() string { return "hpa-upgrade" }
40
41
42 func (t *HPAUpgradeTest) Setup(ctx context.Context, f *framework.Framework) {
43 t.rc = e2eautoscaling.NewDynamicResourceConsumer(ctx,
44 "res-cons-upgrade",
45 f.Namespace.Name,
46 e2eautoscaling.KindRC,
47 1,
48 250,
49 0,
50 0,
51 500,
52 200,
53 f.ClientSet,
54 f.ScalesGetter,
55 e2eautoscaling.Disable,
56 e2eautoscaling.Idle)
57 t.hpa = e2eautoscaling.CreateCPUResourceHorizontalPodAutoscaler(ctx,
58 t.rc,
59 20,
60 1,
61 5)
62
63 t.rc.Pause()
64 t.test(ctx)
65 }
66
67
68 func (t *HPAUpgradeTest) Test(ctx context.Context, f *framework.Framework, done <-chan struct{}, upgrade upgrades.UpgradeType) {
69
70 ginkgo.By(fmt.Sprintf("Waiting for upgrade to finish before checking HPA"))
71 <-done
72 t.test(ctx)
73 }
74
75
76 func (t *HPAUpgradeTest) Teardown(ctx context.Context, f *framework.Framework) {
77
78 e2eautoscaling.DeleteHorizontalPodAutoscaler(ctx, t.rc, t.hpa.Name)
79 t.rc.CleanUp(ctx)
80 }
81
82 func (t *HPAUpgradeTest) test(ctx context.Context) {
83 const timeToWait = 15 * time.Minute
84 t.rc.Resume(ctx)
85
86 ginkgo.By(fmt.Sprintf("HPA scales to 1 replica: consume 10 millicores, target per pod 100 millicores, min pods 1."))
87 t.rc.ConsumeCPU(10)
88 ginkgo.By(fmt.Sprintf("HPA waits for 1 replica"))
89 t.rc.WaitForReplicas(ctx, 1, timeToWait)
90
91 ginkgo.By(fmt.Sprintf("HPA scales to 3 replicas: consume 250 millicores, target per pod 100 millicores."))
92 t.rc.ConsumeCPU(250)
93 ginkgo.By(fmt.Sprintf("HPA waits for 3 replicas"))
94 t.rc.WaitForReplicas(ctx, 3, timeToWait)
95
96 ginkgo.By(fmt.Sprintf("HPA scales to 5 replicas: consume 700 millicores, target per pod 100 millicores, max pods 5."))
97 t.rc.ConsumeCPU(700)
98 ginkgo.By(fmt.Sprintf("HPA waits for 5 replicas"))
99 t.rc.WaitForReplicas(ctx, 5, timeToWait)
100
101
102 t.rc.Pause()
103 }
104
View as plain text