From 2de69768d097546ef25b317a9907f6d4d484e4b7 Mon Sep 17 00:00:00 2001 From: Marco Voelz Date: Wed, 7 Feb 2024 15:56:01 +0100 Subject: [PATCH] Fix e2e test setup --- .../e2e/v1/admission_controller.go | 49 +++++++------------ vertical-pod-autoscaler/e2e/v1/recommender.go | 4 +- .../pkg/utils/test/test_vpa.go | 18 +++++-- .../pkg/utils/test/test_vpa.go | 18 +++++-- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/vertical-pod-autoscaler/e2e/v1/admission_controller.go b/vertical-pod-autoscaler/e2e/v1/admission_controller.go index a2e23bd6abae..efbe09856987 100644 --- a/vertical-pod-autoscaler/e2e/v1/admission_controller.go +++ b/vertical-pod-autoscaler/e2e/v1/admission_controller.go @@ -76,24 +76,24 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") + removedContainerName := "removed" container1Name := GetHamsterContainerNameByIndex(0) - container2Name := GetHamsterContainerNameByIndex(1) vpaCRD := test.VerticalPodAutoscaler(). WithName("hamster-vpa"). WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). - WithContainer(container1Name). + WithContainer(removedContainerName). AppendRecommendation( test.Recommendation(). - WithContainer(container1Name). + WithContainer(removedContainerName). WithTarget("500m", "500Mi"). WithLowerBound("500m", "500Mi"). WithUpperBound("500m", "500Mi"). GetContainerResources()). - WithContainer(container2Name). + WithContainer(container1Name). AppendRecommendation( test.Recommendation(). - WithContainer(container2Name). + WithContainer(container1Name). WithTarget("250m", "200Mi"). WithLowerBound("250m", "200Mi"). WithUpperBound("250m", "200Mi"). @@ -117,15 +117,15 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - containerName := GetHamsterContainerNameByIndex(0) + removedContainerName := "removed" vpaCRD := test.VerticalPodAutoscaler(). WithName("hamster-vpa"). WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). - WithContainer(containerName). + WithContainer(removedContainerName). AppendRecommendation( test.Recommendation(). - WithContainer(containerName). + WithContainer(removedContainerName). WithTarget("250m", "200Mi"). WithLowerBound("250m", "200Mi"). WithUpperBound("250m", "200Mi"). @@ -449,6 +449,7 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). WithContainer(containerName). + WithControlledValues(containerName, vpa_types.ContainerControlledValuesRequestsOnly). AppendRecommendation( test.Recommendation(). WithContainer(containerName). @@ -698,28 +699,20 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - container1Name := GetHamsterContainerNameByIndex(0) - container2Name := GetHamsterContainerNameByIndex(1) + containerName := GetHamsterContainerNameByIndex(0) vpaCRD := test.VerticalPodAutoscaler(). WithName("hamster-vpa"). WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). - WithContainer(container1Name). + WithContainer(containerName). AppendRecommendation( test.Recommendation(). - WithContainer(container1Name). + WithContainer(containerName). 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()). + WithMaxAllowed(containerName, "233m", "150Mi"). Get() InstallVPA(f, vpaCRD) @@ -740,28 +733,20 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() { d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/) ginkgo.By("Setting up a VPA CRD") - container1Name := GetHamsterContainerNameByIndex(0) - container2Name := GetHamsterContainerNameByIndex(1) + containerName := GetHamsterContainerNameByIndex(0) vpaCRD := test.VerticalPodAutoscaler(). WithName("hamster-vpa"). WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). - WithContainer(container1Name). + WithContainer(containerName). AppendRecommendation( test.Recommendation(). - WithContainer(container1Name). + WithContainer(containerName). 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()). + WithMinAllowed(containerName, "90m", "80Mi"). Get() InstallVPA(f, vpaCRD) diff --git a/vertical-pod-autoscaler/e2e/v1/recommender.go b/vertical-pod-autoscaler/e2e/v1/recommender.go index d8b361ee1e6e..696684e39d39 100644 --- a/vertical-pod-autoscaler/e2e/v1/recommender.go +++ b/vertical-pod-autoscaler/e2e/v1/recommender.go @@ -201,7 +201,7 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() { ginkgo.By("Setting up a VPA CRD") containerName := GetHamsterContainerNameByIndex(0) - vpaCRD := test.VerticalPodAutoscaler(). + vpaCRD = test.VerticalPodAutoscaler(). WithName("hamster-vpa"). WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). @@ -315,7 +315,7 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() { WithNamespace(f.Namespace.Name). WithTargetRef(hamsterTargetRef). WithContainer(containerName). - WithMaxAllowed(containerName, "1", ""). + WithMaxAllowed(containerName, "1m", ""). Get() InstallVPA(f, vpaCRD) diff --git a/vertical-pod-autoscaler/e2e/vendor/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go b/vertical-pod-autoscaler/e2e/vendor/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go index 459aed757bdd..6bb3279baff9 100644 --- a/vertical-pod-autoscaler/e2e/vendor/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go +++ b/vertical-pod-autoscaler/e2e/vendor/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go @@ -66,6 +66,7 @@ func VerticalPodAutoscaler() VerticalPodAutoscalerBuilder { minAllowed: map[string]core.ResourceList{}, maxAllowed: map[string]core.ResourceList{}, controlledValues: map[string]*vpa_types.ContainerControlledValues{}, + scalingMode: map[string]*vpa_types.ContainerScalingMode{}, } } @@ -194,18 +195,20 @@ func (b *verticalPodAutoscalerBuilder) WithGroupVersion(gv meta.GroupVersion) Ve } func (b *verticalPodAutoscalerBuilder) WithEvictionRequirements(evictionRequirements []*vpa_types.EvictionRequirement) VerticalPodAutoscalerBuilder { + updateModeAuto := vpa_types.UpdateModeAuto c := *b if c.updatePolicy == nil { - c.updatePolicy = &vpa_types.PodUpdatePolicy{} + c.updatePolicy = &vpa_types.PodUpdatePolicy{UpdateMode: &updateModeAuto} } c.updatePolicy.EvictionRequirements = evictionRequirements return &c } func (b *verticalPodAutoscalerBuilder) WithMinReplicas(minReplicas *int32) VerticalPodAutoscalerBuilder { + updateModeAuto := vpa_types.UpdateModeAuto c := *b if c.updatePolicy == nil { - c.updatePolicy = &vpa_types.PodUpdatePolicy{} + c.updatePolicy = &vpa_types.PodUpdatePolicy{UpdateMode: &updateModeAuto} } c.updatePolicy.MinReplicas = minReplicas return &c @@ -239,14 +242,19 @@ func (b *verticalPodAutoscalerBuilder) Get() *vpa_types.VerticalPodAutoscaler { } resourcePolicy := vpa_types.PodResourcePolicy{} recommendation := &vpa_types.RecommendedPodResources{} + scalingModeAuto := vpa_types.ContainerScalingModeAuto for _, containerName := range b.containerNames { - resourcePolicy.ContainerPolicies = append(resourcePolicy.ContainerPolicies, vpa_types.ContainerResourcePolicy{ + containerResourcePolicy := vpa_types.ContainerResourcePolicy{ ContainerName: containerName, MinAllowed: b.minAllowed[containerName], MaxAllowed: b.maxAllowed[containerName], ControlledValues: b.controlledValues[containerName], - Mode: b.scalingMode[containerName], - }) + Mode: &scalingModeAuto, + } + if scalingMode, ok := b.scalingMode[containerName]; ok { + containerResourcePolicy.Mode = scalingMode + } + resourcePolicy.ContainerPolicies = append(resourcePolicy.ContainerPolicies, containerResourcePolicy) } // VPAs with a single container may still use the old/implicit way of adding recommendations r := b.recommendation.WithContainer(b.containerNames[0]).Get() diff --git a/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go b/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go index 459aed757bdd..6bb3279baff9 100644 --- a/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go +++ b/vertical-pod-autoscaler/pkg/utils/test/test_vpa.go @@ -66,6 +66,7 @@ func VerticalPodAutoscaler() VerticalPodAutoscalerBuilder { minAllowed: map[string]core.ResourceList{}, maxAllowed: map[string]core.ResourceList{}, controlledValues: map[string]*vpa_types.ContainerControlledValues{}, + scalingMode: map[string]*vpa_types.ContainerScalingMode{}, } } @@ -194,18 +195,20 @@ func (b *verticalPodAutoscalerBuilder) WithGroupVersion(gv meta.GroupVersion) Ve } func (b *verticalPodAutoscalerBuilder) WithEvictionRequirements(evictionRequirements []*vpa_types.EvictionRequirement) VerticalPodAutoscalerBuilder { + updateModeAuto := vpa_types.UpdateModeAuto c := *b if c.updatePolicy == nil { - c.updatePolicy = &vpa_types.PodUpdatePolicy{} + c.updatePolicy = &vpa_types.PodUpdatePolicy{UpdateMode: &updateModeAuto} } c.updatePolicy.EvictionRequirements = evictionRequirements return &c } func (b *verticalPodAutoscalerBuilder) WithMinReplicas(minReplicas *int32) VerticalPodAutoscalerBuilder { + updateModeAuto := vpa_types.UpdateModeAuto c := *b if c.updatePolicy == nil { - c.updatePolicy = &vpa_types.PodUpdatePolicy{} + c.updatePolicy = &vpa_types.PodUpdatePolicy{UpdateMode: &updateModeAuto} } c.updatePolicy.MinReplicas = minReplicas return &c @@ -239,14 +242,19 @@ func (b *verticalPodAutoscalerBuilder) Get() *vpa_types.VerticalPodAutoscaler { } resourcePolicy := vpa_types.PodResourcePolicy{} recommendation := &vpa_types.RecommendedPodResources{} + scalingModeAuto := vpa_types.ContainerScalingModeAuto for _, containerName := range b.containerNames { - resourcePolicy.ContainerPolicies = append(resourcePolicy.ContainerPolicies, vpa_types.ContainerResourcePolicy{ + containerResourcePolicy := vpa_types.ContainerResourcePolicy{ ContainerName: containerName, MinAllowed: b.minAllowed[containerName], MaxAllowed: b.maxAllowed[containerName], ControlledValues: b.controlledValues[containerName], - Mode: b.scalingMode[containerName], - }) + Mode: &scalingModeAuto, + } + if scalingMode, ok := b.scalingMode[containerName]; ok { + containerResourcePolicy.Mode = scalingMode + } + resourcePolicy.ContainerPolicies = append(resourcePolicy.ContainerPolicies, containerResourcePolicy) } // VPAs with a single container may still use the old/implicit way of adding recommendations r := b.recommendation.WithContainer(b.containerNames[0]).Get()