diff --git a/vertical-pod-autoscaler/e2e/v1/actuation.go b/vertical-pod-autoscaler/e2e/v1/actuation.go index b38469f2c02b..5bf1871a3889 100644 --- a/vertical-pod-autoscaler/e2e/v1/actuation.go +++ b/vertical-pod-autoscaler/e2e/v1/actuation.go @@ -19,6 +19,7 @@ package autoscaling import ( "context" "fmt" + "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test" "time" appsv1 "k8s.io/api/apps/v1" @@ -265,7 +266,31 @@ var _ = ActuationSuiteE2eDescribe("Actuation", func() { podList := startDeploymentPods(f, d) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "200m", "", "200m", "", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("200m", ""). + WithLowerBound("200m", ""). + WithUpperBound("200m", ""). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("200m", ""). + WithLowerBound("200m", ""). + WithUpperBound("200m", ""). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) // Max CPU limit is 600m per pod, 300m per container and ratio is 3., so max request is 100m, // while recommendation is 200m @@ -282,11 +307,35 @@ var _ = ActuationSuiteE2eDescribe("Actuation", func() { ParseQuantityOrDie("100m") /*cpu request*/, ParseQuantityOrDie("200Mi"), /*memory request*/ ParseQuantityOrDie("300m") /*cpu limit*/, ParseQuantityOrDie("400Mi") /*memory limit*/) d.Spec.Template.Spec.Containers = append(d.Spec.Template.Spec.Containers, d.Spec.Template.Spec.Containers[0]) - d.Spec.Template.Spec.Containers[1].Name = "hamster2" + container2Name := "hamster2" + d.Spec.Template.Spec.Containers[1].Name = container2Name podList := startDeploymentPods(f, d) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "50m", "", "50m", "", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("50m", ""). + WithLowerBound("50m", ""). + WithUpperBound("50m", ""). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("50m", ""). + WithLowerBound("50m", ""). + WithUpperBound("50m", ""). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) // Min CPU from limit range is 200m per pod, 100m per container and ratio is 3. Min applies both // to limit and request so min request is 100m request and 300m limit @@ -327,7 +376,31 @@ var _ = ActuationSuiteE2eDescribe("Actuation", func() { defer webhookCleanup() ginkgo.By("Setting up a hamster vpa") - SetupVPAFor2Containers(f, "100m", "", "5000m", "", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("100m", ""). + WithLowerBound("100m", ""). + WithUpperBound("100m", ""). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("5000m", ""). + WithLowerBound("5000m", ""). + WithUpperBound("5000m", ""). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Setting up a hamster deployment") diff --git a/vertical-pod-autoscaler/e2e/v1/admission_controller.go b/vertical-pod-autoscaler/e2e/v1/admission_controller.go index 98a086e7c34f..e055fb7f9e02 100644 --- a/vertical-pod-autoscaler/e2e/v1/admission_controller.go +++ b/vertical-pod-autoscaler/e2e/v1/admission_controller.go @@ -19,6 +19,7 @@ package autoscaling import ( "context" "fmt" + "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test" "time" appsv1 "k8s.io/api/apps/v1" @@ -60,7 +61,31 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "500m", "500Mi", "250m", "200Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("500m", "500Mi"). + WithLowerBound("500m", "500Mi"). + WithUpperBound("500m", "500Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("250m", "200Mi"). + WithLowerBound("250m", "200Mi"). + WithUpperBound("250m", "200Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Setting up a hamster deployment") podList := startDeploymentPods(f, d) @@ -122,7 +147,31 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { InstallLimitRangeWithMax(f, "300m", "1Gi", apiv1.LimitTypeContainer) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "500m", "500Mi", "250m", "200Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("500m", "500Mi"). + WithLowerBound("500m", "500Mi"). + WithUpperBound("500m", "500Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("250m", "200Mi"). + WithLowerBound("250m", "200Mi"). + WithUpperBound("250m", "200Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Setting up a hamster deployment") podList := startDeploymentPods(f, d) @@ -372,9 +421,34 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { ParseQuantityOrDie("100m") /*cpu request*/, ParseQuantityOrDie("100Mi"), /*memory request*/ ParseQuantityOrDie("150m") /*cpu limit*/, ParseQuantityOrDie("200Mi") /*memory limit*/) d.Spec.Template.Spec.Containers = append(d.Spec.Template.Spec.Containers, d.Spec.Template.Spec.Containers[0]) - d.Spec.Template.Spec.Containers[1].Name = "hamster2" + container2Name := "hamster2" + d.Spec.Template.Spec.Containers[1].Name = container2Name + ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "250m", "200Mi", "250m", "200Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("250m", "200Mi"). + WithLowerBound("250m", "200Mi"). + WithUpperBound("250m", "200Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("250m", "200Mi"). + WithLowerBound("250m", "200Mi"). + WithUpperBound("250m", "200Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) // Max CPU limit is 600m for pod, 300 per container and ratio is 1.5, so max request is 200m, // while recommendation is 250m @@ -403,9 +477,34 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { ParseQuantityOrDie("100m") /*cpu request*/, ParseQuantityOrDie("200Mi"), /*memory request*/ ParseQuantityOrDie("150m") /*cpu limit*/, ParseQuantityOrDie("400Mi") /*memory limit*/) d.Spec.Template.Spec.Containers = append(d.Spec.Template.Spec.Containers, d.Spec.Template.Spec.Containers[0]) - d.Spec.Template.Spec.Containers[1].Name = "hamster2" + container2Name := "hamster2" + d.Spec.Template.Spec.Containers[1].Name = container2Name + ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "120m", "100Mi", "120m", "100Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("120m", "100Mi"). + WithLowerBound("120m", "100Mi"). + WithUpperBound("120m", "100Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("120m", "100Mi"). + WithLowerBound("120m", "100Mi"). + WithUpperBound("120m", "100Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) // Min CPU from limit range is 100m, 50m per pod and ratio is 1.5. Min applies to both limit and // request so min request is 50m and min limit is 75 @@ -434,7 +533,31 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "250m", "200Mi", "233m", "150Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("250m", "200Mi"). + WithLowerBound("250m", "200Mi"). + WithUpperBound("250m", "200Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("233m", "150Mi"). + WithLowerBound("233m", "150Mi"). + WithUpperBound("233m", "150Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Setting up a hamster deployment") podList := startDeploymentPods(f, d) @@ -452,7 +575,31 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - SetupVPAFor2Containers(f, "50m", "60Mi", "90m", "80Mi", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container1Name). + WithTarget("50m", "60Mi"). + WithLowerBound("50m", "60Mi"). + WithUpperBound("50m", "60Mi"). + GetContainerResources()). + WithContainer(container2Name). + AppendRecommendation( + test.Recommendation(). + WithContainer(container2Name). + WithTarget("90m", "80Mi"). + WithLowerBound("90m", "80Mi"). + WithUpperBound("90m", "80Mi"). + GetContainerResources()). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Setting up a hamster deployment") podList := startDeploymentPods(f, d) diff --git a/vertical-pod-autoscaler/e2e/v1/common.go b/vertical-pod-autoscaler/e2e/v1/common.go index 879ae5ad0473..e3f3edb4a9bc 100644 --- a/vertical-pod-autoscaler/e2e/v1/common.go +++ b/vertical-pod-autoscaler/e2e/v1/common.go @@ -319,39 +319,6 @@ func SetupVPA(f *framework.Framework, cpu string, memory string, mode vpa_types. return vpaCRD } -// SetupVPAFor2Containers creates and installs a simple hamster VPA for a pod with n containers, for e2e test purposes. -func SetupVPAFor2Containers(f *framework.Framework, container1CPU string, container1Memory string, container2CPU string, container2Memory string, targetRef *autoscaling.CrossVersionObjectReference, mode vpa_types.UpdateMode, container1ScalingMode vpa_types.ContainerScalingMode, container2ScalingMode vpa_types.ContainerScalingMode) *vpa_types.VerticalPodAutoscaler { - container1Name := GetHamsterContainerNameByIndex(0) - container2Name := GetHamsterContainerNameByIndex(1) - vpaCRD := test.VerticalPodAutoscaler(). - WithName("hamster-vpa"). - WithNamespace(f.Namespace.Name). - WithTargetRef(targetRef). - WithUpdateMode(mode). - WithContainer(container1Name). - WithScalingMode(container1Name, container1ScalingMode). - AppendRecommendation( - test.Recommendation(). - WithContainer(container1Name). - WithTarget(container1CPU, container1Memory). - WithLowerBound(container1CPU, container1Memory). - WithUpperBound(container1CPU, container1Memory). - GetContainerResources()). - WithContainer(container2Name). - WithScalingMode(container2Name, container2ScalingMode). - AppendRecommendation( - test.Recommendation(). - WithContainer(container2Name). - WithTarget(container2CPU, container2Memory). - WithLowerBound(container2CPU, container2Memory). - WithUpperBound(container2CPU, container2Memory). - GetContainerResources()). - Get() - - InstallVPA(f, vpaCRD) - return vpaCRD -} - type patchRecord struct { Op string `json:"op,inline"` Path string `json:"path,inline"` diff --git a/vertical-pod-autoscaler/e2e/v1/recommender.go b/vertical-pod-autoscaler/e2e/v1/recommender.go index f703403bf467..6f637a0e12eb 100644 --- a/vertical-pod-autoscaler/e2e/v1/recommender.go +++ b/vertical-pod-autoscaler/e2e/v1/recommender.go @@ -19,6 +19,7 @@ package autoscaling import ( "context" "fmt" + "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test" "strings" "time" @@ -313,8 +314,19 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() { ginkgo.By("Setting up a hamster deployment") d := NewNHamstersDeployment(f, 2 /*number of containers*/) _ = startDeploymentPods(f, d) + ginkgo.By("Setting up VPA CRD") - vpaCRD := SetupVPAFor2Containers(f, "", "", "", "", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeAuto, vpa_types.ContainerScalingModeAuto) + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + WithContainer(container2Name). + Get() + + InstallVPA(f, vpaCRD) ginkgo.By("Waiting for recommendation to be filled for both containers") vpa, err := WaitForRecommendationPresent(vpaClientSet, vpaCRD) @@ -326,7 +338,21 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() { ginkgo.By("Setting up a hamster deployment") d := NewNHamstersDeployment(f, 2 /*number of containers*/) _ = startDeploymentPods(f, d) - vpaCRD := SetupVPAFor2Containers(f, "", "", "", "", hamsterTargetRef, vpa_types.UpdateModeAuto, vpa_types.ContainerScalingModeOff, vpa_types.ContainerScalingModeAuto) + + ginkgo.By("Setting up VPA CRD") + container1Name := GetHamsterContainerNameByIndex(0) + container2Name := GetHamsterContainerNameByIndex(1) + vpaCRD := test.VerticalPodAutoscaler(). + WithName("hamster-vpa"). + WithNamespace(f.Namespace.Name). + WithTargetRef(hamsterTargetRef). + WithContainer(container1Name). + WithScalingMode(container1Name, vpa_types.ContainerScalingModeOff). + WithContainer(container2Name). + Get() + + InstallVPA(f, vpaCRD) + ginkgo.By("Waiting for recommendation to be filled for just one container") vpa, err := WaitForRecommendationPresent(vpaClientSet, vpaCRD) gomega.Expect(err).NotTo(gomega.HaveOccurred())