@@ -299,4 +299,113 @@ var _ = Describe("StartupCPUBoost", func() {
299299 })
300300 })
301301 })
302+ Describe ("Updates boost from the spec" , func () {
303+ var (
304+ updatedSpec * autoscaling.StartupCPUBoost
305+ )
306+ BeforeEach (func () {
307+ spec .Selector = metav1.LabelSelector {
308+ MatchLabels : map [string ]string {
309+ "app" : "test" ,
310+ },
311+ }
312+ spec .Spec .DurationPolicy .Fixed = & autoscaling.FixedDurationPolicy {
313+ Unit : autoscaling .FixedDurationPolicyUnitMin ,
314+ Value : 2 ,
315+ }
316+ spec .Spec .DurationPolicy .PodCondition = & autoscaling.PodConditionDurationPolicy {
317+ Status : corev1 .ConditionTrue ,
318+ Type : corev1 .PodReady ,
319+ }
320+ updatedSpec = spec .DeepCopy ()
321+ })
322+ JustBeforeEach (func () {
323+ boost , err = cpuboost .NewStartupCPUBoost (nil , spec )
324+ Expect (err ).ShouldNot (HaveOccurred ())
325+ err = boost .UpdateFromSpec (context .TODO (), updatedSpec )
326+ })
327+ When ("selector is changed" , func () {
328+ var (
329+ podToSelect * corev1.Pod
330+ )
331+ BeforeEach (func () {
332+ updatedSpec .Selector = metav1.LabelSelector {
333+ MatchLabels : map [string ]string {
334+ "app" : "newApp" ,
335+ },
336+ }
337+ podToSelect = & corev1.Pod {
338+ ObjectMeta : metav1.ObjectMeta {
339+ Name : "test-pod" ,
340+ Namespace : specTemplate .Namespace ,
341+ Labels : map [string ]string {
342+ "app" : "newApp" ,
343+ }}}
344+ })
345+ It ("matches pod with new selector" , func () {
346+ Expect (boost .Matches (podToSelect )).To (BeTrue ())
347+ })
348+ })
349+ When ("duration policy is changed" , func () {
350+ var (
351+ durationPolicies map [string ]duration.Policy
352+ )
353+ BeforeEach (func () {
354+ updatedSpec .Spec .DurationPolicy .Fixed = & autoscaling.FixedDurationPolicy {
355+ Unit : autoscaling .FixedDurationPolicyUnitMin ,
356+ Value : 1000 ,
357+ }
358+ updatedSpec .Spec .DurationPolicy .PodCondition = & autoscaling.PodConditionDurationPolicy {
359+ Type : corev1 .PodInitialized ,
360+ Status : corev1 .ConditionTrue ,
361+ }
362+ })
363+ JustBeforeEach (func () {
364+ durationPolicies = boost .DurationPolicies ()
365+ })
366+ It ("has valid fixed duration policy" , func () {
367+ durationPolicy := durationPolicies [duration .FixedDurationPolicyName ]
368+ Expect (durationPolicy ).To (BeAssignableToTypeOf (& duration.FixedDurationPolicy {}))
369+ fixedDurationPolicy := durationPolicy .(* duration.FixedDurationPolicy )
370+ Expect (fixedDurationPolicy .Duration ()).To (Equal (1000 * time .Minute ))
371+ })
372+ It ("has valid pod condition policy" , func () {
373+ durationPolicy := durationPolicies [duration .PodConditionPolicyName ]
374+ Expect (durationPolicy ).To (BeAssignableToTypeOf (& duration.PodConditionPolicy {}))
375+ podConditionDurationPolicy := durationPolicy .(* duration.PodConditionPolicy )
376+ Expect (podConditionDurationPolicy .Condition ()).To (Equal (corev1 .PodInitialized ))
377+ Expect (podConditionDurationPolicy .Status ()).To (Equal (corev1 .ConditionTrue ))
378+ })
379+ })
380+ When ("resource policy is changed" , func () {
381+ var (
382+ resourcePolicy resource.ContainerPolicy
383+ resourcePolicyFound bool
384+ )
385+ BeforeEach (func () {
386+ updatedSpec .Spec .ResourcePolicy = autoscaling.ResourcePolicy {
387+ ContainerPolicies : []autoscaling.ContainerPolicy {
388+ {
389+ ContainerName : "test" ,
390+ PercentageIncrease : & autoscaling.PercentageIncrease {
391+ Value : 1000 ,
392+ },
393+ },
394+ },
395+ }
396+
397+ })
398+ JustBeforeEach (func () {
399+ resourcePolicy , resourcePolicyFound = boost .ResourcePolicy ("test" )
400+ })
401+ It ("finds resource policy" , func () {
402+ Expect (resourcePolicyFound ).To (BeTrue ())
403+ })
404+ It ("has valid resource policy" , func () {
405+ Expect (resourcePolicy ).To (BeAssignableToTypeOf (& resource.PercentageContainerPolicy {}))
406+ percentagePolicy := resourcePolicy .(* resource.PercentageContainerPolicy )
407+ Expect (percentagePolicy .Percentage ()).To (Equal (int64 (1000 )))
408+ })
409+ })
410+ })
302411})
0 commit comments