@@ -21,6 +21,7 @@ import (
21
21
autoscaling "github.com/google/kube-startup-cpu-boost/api/v1alpha1"
22
22
cpuboost "github.com/google/kube-startup-cpu-boost/internal/boost"
23
23
"github.com/google/kube-startup-cpu-boost/internal/boost/duration"
24
+ bpod "github.com/google/kube-startup-cpu-boost/internal/boost/pod"
24
25
"github.com/google/kube-startup-cpu-boost/internal/metrics"
25
26
"github.com/google/kube-startup-cpu-boost/internal/mock"
26
27
. "github.com/onsi/ginkgo/v2"
@@ -39,16 +40,17 @@ var _ = Describe("Manager", func() {
39
40
})
40
41
Describe ("Registers startup-cpu-boost" , func () {
41
42
var (
42
- spec * autoscaling.StartupCPUBoost
43
- boost cpuboost.StartupCPUBoost
44
- err error
43
+ spec * autoscaling.StartupCPUBoost
44
+ boost cpuboost.StartupCPUBoost
45
+ useLegacyRevertMode bool
46
+ err error
45
47
)
46
48
BeforeEach (func () {
47
49
spec = specTemplate .DeepCopy ()
48
50
})
49
51
JustBeforeEach (func () {
50
52
manager = cpuboost .NewManager (nil )
51
- boost , err = cpuboost .NewStartupCPUBoost (nil , spec )
53
+ boost , err = cpuboost .NewStartupCPUBoost (nil , spec , useLegacyRevertMode )
52
54
Expect (err ).ToNot (HaveOccurred ())
53
55
})
54
56
When ("startup-cpu-boost exists" , func () {
@@ -81,16 +83,17 @@ var _ = Describe("Manager", func() {
81
83
})
82
84
Describe ("De-registers startup-cpu-boost" , func () {
83
85
var (
84
- spec * autoscaling.StartupCPUBoost
85
- boost cpuboost.StartupCPUBoost
86
- err error
86
+ spec * autoscaling.StartupCPUBoost
87
+ boost cpuboost.StartupCPUBoost
88
+ useLegacyRevertMode bool
89
+ err error
87
90
)
88
91
BeforeEach (func () {
89
92
spec = specTemplate .DeepCopy ()
90
93
})
91
94
JustBeforeEach (func () {
92
95
manager = cpuboost .NewManager (nil )
93
- boost , err = cpuboost .NewStartupCPUBoost (nil , spec )
96
+ boost , err = cpuboost .NewStartupCPUBoost (nil , spec , useLegacyRevertMode )
94
97
Expect (err ).ToNot (HaveOccurred ())
95
98
})
96
99
When ("startup-cpu-boost exists" , func () {
@@ -110,10 +113,11 @@ var _ = Describe("Manager", func() {
110
113
})
111
114
Describe ("updates startup-cpu-boost from spec" , func () {
112
115
var (
113
- boost cpuboost.StartupCPUBoost
114
- err error
115
- spec * autoscaling.StartupCPUBoost
116
- updatedSpec * autoscaling.StartupCPUBoost
116
+ boost cpuboost.StartupCPUBoost
117
+ err error
118
+ useLegacyRevertMode bool
119
+ spec * autoscaling.StartupCPUBoost
120
+ updatedSpec * autoscaling.StartupCPUBoost
117
121
)
118
122
BeforeEach (func () {
119
123
spec = specTemplate .DeepCopy ()
@@ -124,7 +128,7 @@ var _ = Describe("Manager", func() {
124
128
}
125
129
})
126
130
JustBeforeEach (func () {
127
- boost , err = cpuboost .NewStartupCPUBoost (nil , spec )
131
+ boost , err = cpuboost .NewStartupCPUBoost (nil , spec , useLegacyRevertMode )
128
132
Expect (err ).ToNot (HaveOccurred ())
129
133
})
130
134
When ("startup-cpu-boost is registered" , func () {
@@ -148,11 +152,12 @@ var _ = Describe("Manager", func() {
148
152
})
149
153
Describe ("retrieves startup-cpu-boost for a POD" , func () {
150
154
var (
151
- pod * corev1.Pod
152
- podNameLabel string
153
- podNameLabelValue string
154
- boost cpuboost.StartupCPUBoost
155
- found bool
155
+ pod * corev1.Pod
156
+ podNameLabel string
157
+ podNameLabelValue string
158
+ boost cpuboost.StartupCPUBoost
159
+ useLegacyRevertMode bool
160
+ found bool
156
161
)
157
162
BeforeEach (func () {
158
163
podNameLabel = "app.kubernetes.io/name"
@@ -184,7 +189,7 @@ var _ = Describe("Manager", func() {
184
189
spec .Selector = * metav1 .AddLabelToSelector (& metav1.LabelSelector {}, podNameLabel , podNameLabelValue )
185
190
})
186
191
JustBeforeEach (func () {
187
- boost , err = cpuboost .NewStartupCPUBoost (nil , spec )
192
+ boost , err = cpuboost .NewStartupCPUBoost (nil , spec , useLegacyRevertMode )
188
193
Expect (err ).NotTo (HaveOccurred ())
189
194
err = manager .AddStartupCPUBoost (context .TODO (), boost )
190
195
Expect (err ).NotTo (HaveOccurred ())
@@ -242,12 +247,13 @@ var _ = Describe("Manager", func() {
242
247
})
243
248
When ("There are startup-cpu-boosts with fixed duration policy" , func () {
244
249
var (
245
- spec * autoscaling.StartupCPUBoost
246
- boost cpuboost.StartupCPUBoost
247
- pod * corev1.Pod
248
- mockClient * mock.MockClient
249
- mockReconciler * mock.MockReconciler
250
- c chan time.Time
250
+ spec * autoscaling.StartupCPUBoost
251
+ boost cpuboost.StartupCPUBoost
252
+ useLegacyRevertMode bool
253
+ pod * corev1.Pod
254
+ mockClient * mock.MockClient
255
+ mockReconciler * mock.MockReconciler
256
+ c chan time.Time
251
257
)
252
258
BeforeEach (func () {
253
259
spec = specTemplate .DeepCopy ()
@@ -265,13 +271,12 @@ var _ = Describe("Manager", func() {
265
271
c = make (chan time.Time , 1 )
266
272
mockTicker .EXPECT ().Tick ().MinTimes (1 ).Return (c )
267
273
mockTicker .EXPECT ().Stop ().Return ()
268
- mockClient .EXPECT ().Update (gomock .Any (), gomock .Eq (pod )).MinTimes (1 ).Return (nil )
269
274
reconcileReq := reconcile.Request {NamespacedName : types.NamespacedName {Name : spec .Name , Namespace : spec .Namespace }}
270
275
mockReconciler .EXPECT ().Reconcile (gomock .Any (), gomock .Eq (reconcileReq )).Times (1 )
271
276
})
272
277
JustBeforeEach (func () {
273
278
manager .SetStartupCPUBoostReconciler (mockReconciler )
274
- boost , err = cpuboost .NewStartupCPUBoost (mockClient , spec )
279
+ boost , err = cpuboost .NewStartupCPUBoost (mockClient , spec , useLegacyRevertMode )
275
280
Expect (err ).ShouldNot (HaveOccurred ())
276
281
err = boost .UpsertPod (ctx , pod )
277
282
Expect (err ).ShouldNot (HaveOccurred ())
@@ -283,8 +288,30 @@ var _ = Describe("Manager", func() {
283
288
cancel ()
284
289
<- done
285
290
})
286
- It ("doesn't error" , func () {
287
- Expect (err ).NotTo (HaveOccurred ())
291
+ When ("legacy revert mode is not used" , func () {
292
+ var (
293
+ mockSubResourceClient * mock.MockSubResourceClient
294
+ )
295
+ BeforeEach (func () {
296
+ mockSubResourceClient = mock .NewMockSubResourceClient (mockCtrl )
297
+ mockSubResourceClient .EXPECT ().Patch (gomock .Any (), gomock .Eq (pod ),
298
+ gomock .Eq (bpod .NewRevertBootsResourcesPatch ())).Return (nil ).Times (1 )
299
+ mockClient .EXPECT ().SubResource ("resize" ).Return (mockSubResourceClient ).Times (1 )
300
+ mockClient .EXPECT ().Patch (gomock .Any (), gomock .Eq (pod ),
301
+ gomock .Eq (bpod .NewRevertBoostLabelsPatch ())).Return (nil ).Times (1 )
302
+ })
303
+ It ("doesn't error" , func () {
304
+ Expect (err ).NotTo (HaveOccurred ())
305
+ })
306
+ })
307
+ When ("legacy revert mode is used" , func () {
308
+ BeforeEach (func () {
309
+ useLegacyRevertMode = true
310
+ mockClient .EXPECT ().Update (gomock .Any (), gomock .Eq (pod )).MinTimes (1 ).Return (nil )
311
+ })
312
+ It ("doesn't error" , func () {
313
+ Expect (err ).NotTo (HaveOccurred ())
314
+ })
288
315
})
289
316
})
290
317
})
0 commit comments