Skip to content

Commit

Permalink
Merge pull request kubernetes#6511 from voelzmo/fix/vpa-e2e-test-setup
Browse files Browse the repository at this point in the history
Fix e2e test setup
  • Loading branch information
k8s-ci-robot authored Feb 13, 2024
2 parents 7031519 + 2de6976 commit 947cd3f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
49 changes: 17 additions & 32 deletions vertical-pod-autoscaler/e2e/v1/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand All @@ -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").
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions vertical-pod-autoscaler/e2e/v1/recommender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions vertical-pod-autoscaler/pkg/utils/test/test_vpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 947cd3f

Please sign in to comment.