Skip to content

Commit 3665ce2

Browse files
authored
Merge pull request kubernetes#3214 from bskiba/e2e-min
VPA min allowed test should not rely on artificial minimal recommendation
2 parents e0f63c1 + ba8d5e4 commit 3665ce2

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

vertical-pod-autoscaler/e2e/v1/common.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ func WaitForRecommendationPresent(c vpa_clientset.Interface, vpa *vpa_types.Vert
533533
})
534534
}
535535

536+
// WaitForUncappedCPURecommendationAbove pools VPA object until uncapped recommendation is above specified value.
537+
// Returns polled VPA object. On timeout returns error.
538+
func WaitForUncappedCPURecommendationAbove(c vpa_clientset.Interface, vpa *vpa_types.VerticalPodAutoscaler, minMilliCPU int64) (*vpa_types.VerticalPodAutoscaler, error) {
539+
return WaitForVPAMatch(c, vpa, func(vpa *vpa_types.VerticalPodAutoscaler) bool {
540+
if vpa.Status.Recommendation == nil || len(vpa.Status.Recommendation.ContainerRecommendations) == 0 {
541+
return false
542+
}
543+
uncappedCpu := vpa.Status.Recommendation.ContainerRecommendations[0].UncappedTarget[apiv1.ResourceCPU]
544+
return uncappedCpu.MilliValue() > minMilliCPU
545+
})
546+
}
547+
536548
func installLimitRange(f *framework.Framework, minCpuLimit, minMemoryLimit, maxCpuLimit, maxMemoryLimit *resource.Quantity, lrType apiv1.LimitType) {
537549
lr := &apiv1.LimitRange{
538550
ObjectMeta: metav1.ObjectMeta{

vertical-pod-autoscaler/e2e/v1/recommender.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,13 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() {
286286
vpaCRD := createVpaCRDWithMinMaxAllowed(f, nil, maxAllowed)
287287

288288
ginkgo.By("Waiting for recommendation to be filled")
289-
vpa, err := WaitForRecommendationPresent(vpaClientSet, vpaCRD)
290-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
289+
vpa, err := WaitForUncappedCPURecommendationAbove(vpaClientSet, vpaCRD, maxMilliCpu)
290+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), fmt.Sprintf(
291+
"Timed out waiting for uncapped cpu recommendation above %d mCPU", maxMilliCpu))
291292
gomega.Expect(vpa.Status.Recommendation.ContainerRecommendations).Should(gomega.HaveLen(1))
292293
cpu := getMilliCpu(vpa.Status.Recommendation.ContainerRecommendations[0].Target)
293294
gomega.Expect(cpu).Should(gomega.BeNumerically("<=", maxMilliCpu),
294295
fmt.Sprintf("target cpu recommendation should be less than or equal to %dm", maxMilliCpu))
295-
cpuUncapped := getMilliCpu(vpa.Status.Recommendation.ContainerRecommendations[0].UncappedTarget)
296-
gomega.Expect(cpuUncapped).Should(gomega.BeNumerically(">", maxMilliCpu),
297-
fmt.Sprintf("uncapped target cpu recommendation should be greater than %dm", maxMilliCpu))
298296
})
299297
})
300298

vertical-pod-autoscaler/e2e/v1beta2/common.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ func WaitForRecommendationPresent(c vpa_clientset.Interface, vpa *vpa_types.Vert
533533
})
534534
}
535535

536+
// WaitForUncappedCPURecommendationAbove pools VPA object until uncapped recommendation is above specified value.
537+
// Returns polled VPA object. On timeout returns error.
538+
func WaitForUncappedCPURecommendationAbove(c vpa_clientset.Interface, vpa *vpa_types.VerticalPodAutoscaler, minMilliCPU int64) (*vpa_types.VerticalPodAutoscaler, error) {
539+
return WaitForVPAMatch(c, vpa, func(vpa *vpa_types.VerticalPodAutoscaler) bool {
540+
if vpa.Status.Recommendation == nil || len(vpa.Status.Recommendation.ContainerRecommendations) == 0 {
541+
return false
542+
}
543+
uncappedCpu := vpa.Status.Recommendation.ContainerRecommendations[0].UncappedTarget[apiv1.ResourceCPU]
544+
return uncappedCpu.MilliValue() > minMilliCPU
545+
})
546+
}
547+
536548
func installLimitRange(f *framework.Framework, minCpuLimit, minMemoryLimit, maxCpuLimit, maxMemoryLimit *resource.Quantity, lrType apiv1.LimitType) {
537549
lr := &apiv1.LimitRange{
538550
ObjectMeta: metav1.ObjectMeta{

vertical-pod-autoscaler/e2e/v1beta2/recommender.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,14 @@ var _ = RecommenderE2eDescribe("VPA CRD object", func() {
286286
vpaCRD := createVpaCRDWithMinMaxAllowed(f, nil, maxAllowed)
287287

288288
ginkgo.By("Waiting for recommendation to be filled")
289-
vpa, err := WaitForRecommendationPresent(vpaClientSet, vpaCRD)
289+
vpa, err := WaitForUncappedCPURecommendationAbove(vpaClientSet, vpaCRD, maxMilliCpu)
290+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), fmt.Sprintf(
291+
"Timed out waiting for uncapped cpu recommendation above %d mCPU", maxMilliCpu))
290292
gomega.Expect(err).NotTo(gomega.HaveOccurred())
291293
gomega.Expect(vpa.Status.Recommendation.ContainerRecommendations).Should(gomega.HaveLen(1))
292294
cpu := getMilliCpu(vpa.Status.Recommendation.ContainerRecommendations[0].Target)
293295
gomega.Expect(cpu).Should(gomega.BeNumerically("<=", maxMilliCpu),
294296
fmt.Sprintf("target cpu recommendation should be less than or equal to %dm", maxMilliCpu))
295-
cpuUncapped := getMilliCpu(vpa.Status.Recommendation.ContainerRecommendations[0].UncappedTarget)
296-
gomega.Expect(cpuUncapped).Should(gomega.BeNumerically(">", maxMilliCpu),
297-
fmt.Sprintf("uncapped target cpu recommendation should be greater than %dm", maxMilliCpu))
298297
})
299298
})
300299

0 commit comments

Comments
 (0)