Skip to content

Commit

Permalink
Inline SetupVPAFor2Containers
Browse files Browse the repository at this point in the history
  • Loading branch information
voelzmo committed Aug 15, 2023
1 parent e675f0e commit f6aacee
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 47 deletions.
81 changes: 77 additions & 4 deletions vertical-pod-autoscaler/e2e/v1/actuation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")

Expand Down
163 changes: 155 additions & 8 deletions vertical-pod-autoscaler/e2e/v1/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
33 changes: 0 additions & 33 deletions vertical-pod-autoscaler/e2e/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Loading

0 comments on commit f6aacee

Please sign in to comment.