@@ -28,6 +28,7 @@ import (
2828 apiv1 "k8s.io/api/core/v1"
2929 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030 vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
31+ "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
3132 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3233 "k8s.io/kubernetes/test/e2e/framework"
3334 framework_deployment "k8s.io/kubernetes/test/e2e/framework/deployment"
@@ -961,6 +962,123 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
961962 })
962963})
963964
965+ var _ = AdmissionControllerE2eDescribe ("Admission-controller" , ginkgo .Label ("FG:CPUStartupBoost" ), func () {
966+ f := framework .NewDefaultFramework ("vertical-pod-autoscaling" )
967+ f .NamespacePodSecurityEnforceLevel = podsecurity .LevelBaseline
968+
969+ ginkgo .BeforeEach (func () {
970+ checkFeatureGateTestsEnabled (f , features .CPUStartupBoost , true , false )
971+ waitForVpaWebhookRegistration (f )
972+ })
973+
974+ ginkgo .It ("boosts CPU by factor on pod creation" , func () {
975+ initialCPU := ParseQuantityOrDie ("100m" )
976+ expectedCPU := ParseQuantityOrDie ("200m" )
977+ d := NewHamsterDeploymentWithResources (f , initialCPU , ParseQuantityOrDie ("100Mi" ))
978+
979+ ginkgo .By ("Setting up a VPA with a startup boost policy (factor)" )
980+ containerName := GetHamsterContainerNameByIndex (0 )
981+ factor := int32 (2 )
982+ vpaCRD := test .VerticalPodAutoscaler ().
983+ WithName ("hamster-vpa" ).
984+ WithNamespace (f .Namespace .Name ).
985+ WithTargetRef (hamsterTargetRef ).
986+ WithContainer (containerName ).
987+ WithCPUStartupBoost (vpa_types .FactorStartupBoostType , & factor , nil , "15s" ).
988+ AppendRecommendation (
989+ test .Recommendation ().
990+ WithContainer (containerName ).
991+ WithTarget ("100m" , "100Mi" ).
992+ GetContainerResources (),
993+ ).
994+ Get ()
995+ InstallVPA (f , vpaCRD )
996+
997+ ginkgo .By ("Starting the deployment and verifying the pod is boosted" )
998+ podList := startDeploymentPods (f , d )
999+ pod := podList .Items [0 ]
1000+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Requests .Cpu ().Cmp (expectedCPU )).To (gomega .Equal (0 ))
1001+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Limits .Cpu ().Cmp (expectedCPU )).To (gomega .Equal (0 ))
1002+ })
1003+
1004+ ginkgo .It ("boosts CPU by quantity on pod creation" , func () {
1005+ initialCPU := ParseQuantityOrDie ("100m" )
1006+ boostCPUQuantity := ParseQuantityOrDie ("500m" )
1007+ expectedCPU := ParseQuantityOrDie ("600m" )
1008+ d := NewHamsterDeploymentWithResources (f , initialCPU , ParseQuantityOrDie ("100Mi" ))
1009+
1010+ ginkgo .By ("Setting up a VPA with a startup boost policy (quantity)" )
1011+ containerName := GetHamsterContainerNameByIndex (0 )
1012+ vpaCRD := test .VerticalPodAutoscaler ().
1013+ WithName ("hamster-vpa" ).
1014+ WithNamespace (f .Namespace .Name ).
1015+ WithTargetRef (hamsterTargetRef ).
1016+ WithContainer (containerName ).
1017+ WithCPUStartupBoost (vpa_types .QuantityStartupBoostType , nil , & boostCPUQuantity , "15s" ).
1018+ AppendRecommendation (
1019+ test .Recommendation ().
1020+ WithContainer (containerName ).
1021+ WithTarget ("100m" , "100Mi" ).
1022+ GetContainerResources (),
1023+ ).
1024+ Get ()
1025+ InstallVPA (f , vpaCRD )
1026+
1027+ ginkgo .By ("Starting the deployment and verifying the pod is boosted" )
1028+ podList := startDeploymentPods (f , d )
1029+ pod := podList .Items [0 ]
1030+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Requests .Cpu ().Cmp (expectedCPU )).To (gomega .Equal (0 ))
1031+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Limits .Cpu ().Cmp (expectedCPU )).To (gomega .Equal (0 ))
1032+ })
1033+
1034+ ginkgo .It ("boosts CPU on pod creation when VPA update mode is Off" , func () {
1035+ initialCPU := ParseQuantityOrDie ("100m" )
1036+ expectedCPU := ParseQuantityOrDie ("200m" )
1037+ d := NewHamsterDeploymentWithResources (f , initialCPU , ParseQuantityOrDie ("100Mi" ))
1038+
1039+ ginkgo .By ("Setting up a VPA with updateMode Off and a startup boost policy" )
1040+ containerName := GetHamsterContainerNameByIndex (0 )
1041+ factor := int32 (2 )
1042+ vpaCRD := test .VerticalPodAutoscaler ().
1043+ WithName ("hamster-vpa" ).
1044+ WithNamespace (f .Namespace .Name ).
1045+ WithTargetRef (hamsterTargetRef ).
1046+ WithContainer (containerName ).
1047+ WithUpdateMode (vpa_types .UpdateModeOff ). // VPA is off, but boost should still work
1048+ WithCPUStartupBoost (vpa_types .FactorStartupBoostType , & factor , nil , "15s" ).
1049+ Get ()
1050+ InstallVPA (f , vpaCRD )
1051+
1052+ ginkgo .By ("Starting the deployment and verifying the pod is boosted" )
1053+ podList := startDeploymentPods (f , d )
1054+ pod := podList .Items [0 ]
1055+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Requests .Cpu ().Cmp (expectedCPU )).To (gomega .Equal (0 ))
1056+ })
1057+
1058+ ginkgo .It ("doesn't boost CPU on pod creation when scaling mode is Off" , func () {
1059+ initialCPU := ParseQuantityOrDie ("100m" )
1060+ d := NewHamsterDeploymentWithResources (f , initialCPU , ParseQuantityOrDie ("100Mi" ))
1061+
1062+ ginkgo .By ("Setting up a VPA with a startup boost policy and scaling mode Off" )
1063+ containerName := GetHamsterContainerNameByIndex (0 )
1064+ factor := int32 (2 )
1065+ vpaCRD := test .VerticalPodAutoscaler ().
1066+ WithName ("hamster-vpa" ).
1067+ WithNamespace (f .Namespace .Name ).
1068+ WithTargetRef (hamsterTargetRef ).
1069+ WithContainer (containerName ).
1070+ WithCPUStartupBoost (vpa_types .FactorStartupBoostType , & factor , nil , "15s" ).
1071+ WithScalingMode (containerName , vpa_types .ContainerScalingModeOff ).
1072+ Get ()
1073+ InstallVPA (f , vpaCRD )
1074+
1075+ ginkgo .By ("Starting the deployment and verifying the pod is NOT boosted" )
1076+ podList := startDeploymentPods (f , d )
1077+ pod := podList .Items [0 ]
1078+ gomega .Expect (pod .Spec .Containers [0 ].Resources .Requests .Cpu ().Cmp (initialCPU )).To (gomega .Equal (0 ))
1079+ })
1080+ })
1081+
9641082func startDeploymentPods (f * framework.Framework , deployment * appsv1.Deployment ) * apiv1.PodList {
9651083 // Apiserver watch can lag depending on cached object count and apiserver resource usage.
9661084 // We assume that watch can lag up to 5 seconds.
0 commit comments