@@ -17,7 +17,6 @@ limitations under the License.
17
17
package autoscaler
18
18
19
19
import (
20
- "fmt"
21
20
"time"
22
21
23
22
. "github.com/onsi/ginkgo/v2"
@@ -83,9 +82,8 @@ var _ = Describe("MostWantedTwoPhaseHysteresisEvaluation Controller", func() {
83
82
Name : "N/A" ,
84
83
},
85
84
},
86
- PollingPeriod : metav1.Duration {Duration : time .Minute },
87
- StabilizationPeriod : metav1.Duration {Duration : time .Hour },
88
- MinimumSampleSize : 5 ,
85
+ PollingPeriod : metav1.Duration {Duration : time .Second },
86
+ StabilizationPeriod : metav1.Duration {Duration : 5 * time .Minute },
89
87
},
90
88
},
91
89
).Create ()
@@ -207,45 +205,8 @@ var _ = Describe("MostWantedTwoPhaseHysteresisEvaluation Controller", func() {
207
205
).
208
206
BranchFailureToUpdateStatusCheck (collector .Collect ).
209
207
WithCheck (
210
- "bail out on minimum sample size not reached " ,
208
+ "succeed " ,
211
209
func (run * ScenarioRun [* autoscalerv1alpha1.MostWantedTwoPhaseHysteresisEvaluation ]) {
212
- samplePartition := NewObjectContainer (
213
- run ,
214
- & autoscalerv1alpha1.LongestProcessingTimePartition {
215
- ObjectMeta : metav1.ObjectMeta {
216
- Name : run .Container ().Get ().Object ().Spec .PartitionProviderRef .Name ,
217
- Namespace : run .Namespace ().ObjectKey ().Name ,
218
- },
219
- },
220
- )
221
- for i := 0 ; i < int (run .Container ().Object ().Spec .MinimumSampleSize - 1 ); i ++ {
222
- Expect (run .ReconcileError ()).ToNot (HaveOccurred ())
223
- Expect (run .ReconcileResult ().RequeueAfter ).
224
- To (Equal (run .Container ().Object ().Spec .PollingPeriod .Duration ))
225
- Expect (run .ReconcileResult ().Requeue ).To (BeFalse ())
226
-
227
- By ("Checking conditions" )
228
- readyCondition := meta .FindStatusCondition (
229
- run .Container ().Get ().Object ().Status .Conditions ,
230
- StatusTypeReady ,
231
- )
232
- Expect (readyCondition ).NotTo (BeNil ())
233
- Expect (readyCondition .Status ).To (Equal (metav1 .ConditionFalse ))
234
- Expect (readyCondition .Reason ).To (Equal ("MinimumSampleSizeNotReached" ))
235
- Expect (readyCondition .Message ).To (ContainSubstring ("Minimum sample size not reached" ))
236
-
237
- By ("Checking history records" )
238
- samplePartition .Get ()
239
- history := run .Container ().Object ().Status .History
240
- Expect (history ).To (HaveLen (i + 1 ))
241
- record := history [i ]
242
- Expect (record .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
243
-
244
- By ("Reconciling resource sample #" + fmt .Sprintf ("%d" , i + 2 ))
245
- time .Sleep (5 * time .Second )
246
- run .Reconcile ()
247
- }
248
-
249
210
Expect (run .ReconcileError ()).ToNot (HaveOccurred ())
250
211
Expect (run .ReconcileResult ().RequeueAfter ).
251
212
To (Equal (run .Container ().Object ().Spec .PollingPeriod .Duration ))
@@ -261,57 +222,28 @@ var _ = Describe("MostWantedTwoPhaseHysteresisEvaluation Controller", func() {
261
222
Expect (readyCondition .Reason ).To (Equal (StatusTypeReady ))
262
223
263
224
By ("Checking history records" )
225
+ samplePartition := NewObjectContainer (
226
+ run ,
227
+ & autoscalerv1alpha1.LongestProcessingTimePartition {
228
+ ObjectMeta : metav1.ObjectMeta {
229
+ Name : run .Container ().Get ().Object ().Spec .PartitionProviderRef .Name ,
230
+ Namespace : run .Namespace ().ObjectKey ().Name ,
231
+ },
232
+ },
233
+ )
264
234
samplePartition .Get ()
265
235
history := run .Container ().Object ().Status .History
266
- Expect (history ).To (HaveLen (int (run .Container ().Object ().Spec .MinimumSampleSize )))
267
- record := history [int (run .Container ().Object ().Spec .MinimumSampleSize )- 1 ]
268
- Expect (record .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
236
+ Expect (history ).To (HaveLen (1 ))
269
237
270
238
By ("Checking evaluation results" )
271
- Expect (run .Container ().Object ().Status .LastEvaluationTimestamp .Time ).To (BeTemporally ("~" , time .Now (), 2 * time .Second ))
272
- Expect (run .Container ().Object ().Status .Projection ).To (Equal (samplePartition .Object ().Status .Replicas ))
273
239
Expect (run .Container ().Object ().Status .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
240
+ Expect (run .Container ().Object ().Status .Projection ).To (Equal (samplePartition .Object ().Status .Replicas ))
241
+ Expect (run .Container ().Object ().Status .LastEvaluationTimestamp .Time ).
242
+ To (BeTemporally ("~" , time .Now (), time .Second ))
274
243
275
- By ("Simulate stabilization period expiring" )
276
- run .Container ().Object ().Status .LastEvaluationTimestamp = & metav1.Time {
277
- Time : time .Now ().Add (- run .Container ().Object ().Spec .StabilizationPeriod .Duration ).
278
- Add (- time .Second ),
279
- }
280
- for i := range run .Container ().Object ().Status .History {
281
- run .Container ().Object ().Status .History [i ].Timestamp = * run .Container ().Object ().Status .LastEvaluationTimestamp
282
- }
283
- run .Container ().StatusUpdate ()
284
-
285
- for i := 0 ; i < int (run .Container ().Object ().Spec .MinimumSampleSize - 1 ); i ++ {
286
- By ("Reconciling resource sample #" + fmt .Sprintf ("%d" , i + 1 ))
287
- time .Sleep (5 * time .Second )
288
- run .Reconcile ()
289
-
290
- Expect (run .ReconcileError ()).ToNot (HaveOccurred ())
291
- Expect (run .ReconcileResult ().RequeueAfter ).
292
- To (Equal (run .Container ().Object ().Spec .PollingPeriod .Duration ))
293
- Expect (run .ReconcileResult ().Requeue ).To (BeFalse ())
294
-
295
- By ("Checking conditions" )
296
- readyCondition := meta .FindStatusCondition (
297
- run .Container ().Get ().Object ().Status .Conditions ,
298
- StatusTypeReady ,
299
- )
300
- Expect (readyCondition ).NotTo (BeNil ())
301
- Expect (readyCondition .Status ).To (Equal (metav1 .ConditionFalse ))
302
- Expect (readyCondition .Reason ).To (Equal ("MinimumSampleSizeNotReached" ))
303
- Expect (readyCondition .Message ).To (ContainSubstring ("Minimum sample size not reached" ))
304
-
305
- By ("Checking history records" )
306
- samplePartition .Get ()
307
- history := run .Container ().Object ().Status .History
308
- Expect (history ).To (HaveLen (i + 1 ))
309
- record := history [i ]
310
- Expect (record .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
311
- }
312
-
313
- By ("Reconciling resource sample #" + fmt .Sprintf ("%d" , run .Container ().Object ().Spec .MinimumSampleSize ))
314
- time .Sleep (5 * time .Second )
244
+ By ("Checking seconds reconciliation" )
245
+ firstReconcileTime := run .Container ().Object ().Status .LastEvaluationTimestamp .Time
246
+ time .Sleep (6 * time .Second )
315
247
run .Reconcile ()
316
248
317
249
Expect (run .ReconcileError ()).ToNot (HaveOccurred ())
@@ -329,27 +261,28 @@ var _ = Describe("MostWantedTwoPhaseHysteresisEvaluation Controller", func() {
329
261
Expect (readyCondition .Reason ).To (Equal (StatusTypeReady ))
330
262
331
263
By ("Checking history records" )
264
+ samplePartition = NewObjectContainer (
265
+ run ,
266
+ & autoscalerv1alpha1.LongestProcessingTimePartition {
267
+ ObjectMeta : metav1.ObjectMeta {
268
+ Name : run .Container ().Get ().Object ().Spec .PartitionProviderRef .Name ,
269
+ Namespace : run .Namespace ().ObjectKey ().Name ,
270
+ },
271
+ },
272
+ )
332
273
samplePartition .Get ()
333
274
history = run .Container ().Object ().Status .History
334
- Expect (history ).To (HaveLen (int (run .Container ().Object ().Spec .MinimumSampleSize )))
335
- record = history [int (run .Container ().Object ().Spec .MinimumSampleSize )- 1 ]
336
- Expect (record .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
275
+ Expect (history ).To (HaveLen (1 ))
276
+ Expect (history [0 ].SeenTimes ).To (Equal (int32 (2 )))
337
277
338
278
By ("Checking evaluation results" )
339
- Expect (run .Container ().Object ().Status .LastEvaluationTimestamp .Time ).To (BeTemporally ("~" , time .Now (), 2 * time .Second ))
340
- Expect (run .Container ().Object ().Status .Projection ).To (Equal (samplePartition .Object ().Status .Replicas ))
341
279
Expect (run .Container ().Object ().Status .Replicas ).To (Equal (samplePartition .Object ().Status .Replicas ))
280
+ Expect (run .Container ().Object ().Status .Projection ).To (Equal (samplePartition .Object ().Status .Replicas ))
281
+ Expect (run .Container ().Object ().Status .LastEvaluationTimestamp .Time ).
282
+ To (Equal (firstReconcileTime ))
342
283
},
343
284
).
344
- Commit (collector .Collect ).
345
- Hydrate (
346
- "with one min sample requirement" ,
347
- func (run * ScenarioRun [* autoscalerv1alpha1.MostWantedTwoPhaseHysteresisEvaluation ]) {
348
- run .Container ().Object ().Spec .MinimumSampleSize = 1
349
- run .Container ().Update ()
350
- },
351
- ).
352
- BranchFailureToUpdateStatusCheck (collector .Collect )
285
+ Commit (collector .Collect )
353
286
354
287
BeforeEach (func () {
355
288
scenarioRun = collector .NewRun (ctx , k8sClient )
0 commit comments