@@ -27,6 +27,7 @@ import (
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
28
"k8s.io/apimachinery/pkg/util/wait"
29
29
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
30
+ "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
30
31
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
31
32
"k8s.io/kubernetes/test/e2e/framework"
32
33
podsecurity "k8s.io/pod-security-admission/api"
@@ -63,7 +64,7 @@ var _ = FullVpaE2eDescribe("Pods under VPA", func() {
63
64
64
65
ginkgo .Describe ("with InPlaceOrRecreate update mode" , ginkgo .Label ("FG:InPlaceOrRecreate" ), func () {
65
66
ginkgo .BeforeEach (func () {
66
- checkInPlaceOrRecreateTestsEnabled ( f , true , false )
67
+ checkFeatureGateTestsEnabled ( f , features . InPlaceOrRecreate , true , false )
67
68
68
69
ns := f .Namespace .Name
69
70
ginkgo .By ("Setting up a hamster deployment" )
@@ -347,6 +348,123 @@ var _ = FullVpaE2eDescribe("Pods under VPA with non-recognized recommender expli
347
348
})
348
349
})
349
350
351
+ var _ = FullVpaE2eDescribe ("Pods under VPA with CPUStartupBoost" , ginkgo .Label ("FG:CPUStartupBoost" ), func () {
352
+ var (
353
+ rc * ResourceConsumer
354
+ )
355
+ replicas := 3
356
+
357
+ ginkgo .AfterEach (func () {
358
+ rc .CleanUp ()
359
+ })
360
+
361
+ f := framework .NewDefaultFramework ("vertical-pod-autoscaling" )
362
+ f .NamespacePodSecurityEnforceLevel = podsecurity .LevelBaseline
363
+
364
+ ginkgo .Describe ("have CPU startup boost recommendation applied" , func () {
365
+ ginkgo .BeforeEach (func () {
366
+ checkFeatureGateTestsEnabled (f , features .CPUStartupBoost , true , true )
367
+ waitForVpaWebhookRegistration (f )
368
+ })
369
+
370
+ ginkgo .It ("to all containers of a pod" , func () {
371
+ ns := f .Namespace .Name
372
+ ginkgo .By ("Setting up a VPA CRD with CPUStartupBoost" )
373
+ targetRef := & autoscaling.CrossVersionObjectReference {
374
+ APIVersion : "apps/v1" ,
375
+ Kind : "Deployment" ,
376
+ Name : "hamster" ,
377
+ }
378
+
379
+ containerName := GetHamsterContainerNameByIndex (0 )
380
+ factor := int32 (100 )
381
+ vpaCRD := test .VerticalPodAutoscaler ().
382
+ WithName ("hamster-vpa" ).
383
+ WithNamespace (f .Namespace .Name ).
384
+ WithTargetRef (targetRef ).
385
+ WithUpdateMode (vpa_types .UpdateModeInPlaceOrRecreate ).
386
+ WithContainer (containerName ).
387
+ WithCPUStartupBoost (& factor , nil , "10s" ).
388
+ Get ()
389
+
390
+ InstallVPA (f , vpaCRD )
391
+
392
+ ginkgo .By ("Setting up a hamster deployment" )
393
+ rc = NewDynamicResourceConsumer ("hamster" , ns , KindDeployment ,
394
+ replicas ,
395
+ 1 , /*initCPUTotal*/
396
+ 10 , /*initMemoryTotal*/
397
+ 1 , /*initCustomMetric*/
398
+ initialCPU , /*cpuRequest*/
399
+ initialMemory , /*memRequest*/
400
+ f .ClientSet ,
401
+ f .ScalesGetter )
402
+
403
+ // Pods should be created with boosted CPU (10m * 100 = 1000m)
404
+ err := waitForResourceRequestInRangeInPods (
405
+ f , pollTimeout , metav1.ListOptions {LabelSelector : "name=hamster" }, apiv1 .ResourceCPU ,
406
+ ParseQuantityOrDie ("800m" ), ParseQuantityOrDie ("1200m" ))
407
+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
408
+
409
+ // Pods should be scaled back down in-place after they become Ready and
410
+ // StartupBoost.CPU.Duration has elapsed
411
+ err = waitForResourceRequestInRangeInPods (
412
+ f , pollTimeout , metav1.ListOptions {LabelSelector : "name=hamster" }, apiv1 .ResourceCPU ,
413
+ ParseQuantityOrDie (minimalCPULowerBound ), ParseQuantityOrDie (minimalCPUUpperBound ))
414
+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
415
+ })
416
+
417
+ ginkgo .It ("to a subset of containers in a pod" , func () {
418
+ ns := f .Namespace .Name
419
+
420
+ ginkgo .By ("Setting up a VPA CRD with CPUStartupBoost" )
421
+ targetRef := & autoscaling.CrossVersionObjectReference {
422
+ APIVersion : "apps/v1" ,
423
+ Kind : "Deployment" ,
424
+ Name : "hamster" ,
425
+ }
426
+
427
+ containerName := GetHamsterContainerNameByIndex (0 )
428
+ factor := int32 (100 )
429
+ vpaCRD := test .VerticalPodAutoscaler ().
430
+ WithName ("hamster-vpa" ).
431
+ WithNamespace (f .Namespace .Name ).
432
+ WithTargetRef (targetRef ).
433
+ WithUpdateMode (vpa_types .UpdateModeInPlaceOrRecreate ).
434
+ WithContainer (containerName ).
435
+ WithCPUStartupBoost (& factor , nil , "10s" ).
436
+ Get ()
437
+
438
+ InstallVPA (f , vpaCRD )
439
+
440
+ ginkgo .By ("Setting up a hamster deployment" )
441
+ rc = NewDynamicResourceConsumer ("hamster" , ns , KindDeployment ,
442
+ replicas ,
443
+ 1 , /*initCPUTotal*/
444
+ 10 , /*initMemoryTotal*/
445
+ 1 , /*initCustomMetric*/
446
+ initialCPU , /*cpuRequest*/
447
+ initialMemory , /*memRequest*/
448
+ f .ClientSet ,
449
+ f .ScalesGetter )
450
+
451
+ // Pods should be created with boosted CPU (10m * 100 = 1000m)
452
+ err := waitForResourceRequestInRangeInPods (
453
+ f , pollTimeout , metav1.ListOptions {LabelSelector : "name=hamster" }, apiv1 .ResourceCPU ,
454
+ ParseQuantityOrDie ("999m" ), ParseQuantityOrDie ("1001m" ))
455
+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
456
+
457
+ // Pods should be scaled back down in-place after they become Ready and
458
+ // StartupBoost.CPU.Duration has elapsed
459
+ err = waitForResourceRequestInRangeInPods (
460
+ f , pollTimeout , metav1.ListOptions {LabelSelector : "name=hamster" }, apiv1 .ResourceCPU ,
461
+ ParseQuantityOrDie (minimalCPULowerBound ), ParseQuantityOrDie (minimalCPUUpperBound ))
462
+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
463
+ })
464
+ })
465
+
466
+ })
467
+
350
468
var _ = FullVpaE2eDescribe ("OOMing pods under VPA" , func () {
351
469
const replicas = 3
352
470
0 commit comments