Skip to content

Commit 4f18830

Browse files
committed
VPA: refactor e2e test ginkgo wrapper functions
This commit refactors the VPA e2e test ginkgo wrappers so that they we can easily supply ginkgo decorators. This allows us to add ginkgo v2 labels to suites so that later we can run tests that only run FG tests. For now, this would only be useful for FG:InPlaceOrRecreate Signed-off-by: Max Cao <[email protected]>
1 parent 087e946 commit 4f18830

File tree

5 files changed

+61
-58
lines changed

5 files changed

+61
-58
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import (
5151
"github.com/onsi/gomega"
5252
)
5353

54-
var _ = ActuationSuiteE2eDescribe("Actuation [InPlaceOrRecreate]", func() {
54+
var _ = ActuationSuiteE2eDescribe("Actuation", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
5555
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
5656
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
5757

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

+43-35
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,49 @@ const (
4242
webhookName = "vpa.k8s.io"
4343
)
4444

45+
var _ = AdmissionControllerE2eDescribe("Admission-controller", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
46+
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
47+
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
48+
49+
ginkgo.BeforeEach(func() {
50+
checkInPlaceOrRecreateTestsEnabled(f, true, false)
51+
waitForVpaWebhookRegistration(f)
52+
})
53+
54+
ginkgo.It("starts pods with new recommended request with InPlaceOrRecreate mode", func() {
55+
d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/)
56+
57+
ginkgo.By("Setting up a VPA CRD")
58+
containerName := GetHamsterContainerNameByIndex(0)
59+
vpaCRD := test.VerticalPodAutoscaler().
60+
WithName("hamster-vpa").
61+
WithNamespace(f.Namespace.Name).
62+
WithTargetRef(hamsterTargetRef).
63+
WithContainer(containerName).
64+
WithUpdateMode(vpa_types.UpdateModeInPlaceOrRecreate).
65+
AppendRecommendation(
66+
test.Recommendation().
67+
WithContainer(containerName).
68+
WithTarget("250m", "200Mi").
69+
WithLowerBound("250m", "200Mi").
70+
WithUpperBound("250m", "200Mi").
71+
GetContainerResources()).
72+
Get()
73+
74+
InstallVPA(f, vpaCRD)
75+
76+
ginkgo.By("Setting up a hamster deployment")
77+
podList := startDeploymentPods(f, d)
78+
79+
// Originally Pods had 100m CPU, 100Mi of memory, but admission controller
80+
// should change it to recommended 250m CPU and 200Mi of memory.
81+
for _, pod := range podList.Items {
82+
gomega.Expect(pod.Spec.Containers[0].Resources.Requests[apiv1.ResourceCPU]).To(gomega.Equal(ParseQuantityOrDie("250m")))
83+
gomega.Expect(pod.Spec.Containers[0].Resources.Requests[apiv1.ResourceMemory]).To(gomega.Equal(ParseQuantityOrDie("200Mi")))
84+
}
85+
})
86+
})
87+
4588
var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
4689
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
4790
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
@@ -916,41 +959,6 @@ var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
916959
gomega.Expect(err).To(gomega.HaveOccurred(), "Invalid VPA object accepted")
917960
gomega.Expect(err.Error()).To(gomega.MatchRegexp(`.*admission webhook .*vpa.* denied the request: .*`), "Admission controller did not inspect the object")
918961
})
919-
920-
ginkgo.It("starts pods with new recommended request with InPlaceOrRecreate mode", func() {
921-
checkInPlaceOrRecreateTestsEnabled(f, true, false)
922-
923-
d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/)
924-
925-
ginkgo.By("Setting up a VPA CRD")
926-
containerName := GetHamsterContainerNameByIndex(0)
927-
vpaCRD := test.VerticalPodAutoscaler().
928-
WithName("hamster-vpa").
929-
WithNamespace(f.Namespace.Name).
930-
WithTargetRef(hamsterTargetRef).
931-
WithContainer(containerName).
932-
WithUpdateMode(vpa_types.UpdateModeInPlaceOrRecreate).
933-
AppendRecommendation(
934-
test.Recommendation().
935-
WithContainer(containerName).
936-
WithTarget("250m", "200Mi").
937-
WithLowerBound("250m", "200Mi").
938-
WithUpperBound("250m", "200Mi").
939-
GetContainerResources()).
940-
Get()
941-
942-
InstallVPA(f, vpaCRD)
943-
944-
ginkgo.By("Setting up a hamster deployment")
945-
podList := startDeploymentPods(f, d)
946-
947-
// Originally Pods had 100m CPU, 100Mi of memory, but admission controller
948-
// should change it to recommended 250m CPU and 200Mi of memory.
949-
for _, pod := range podList.Items {
950-
gomega.Expect(pod.Spec.Containers[0].Resources.Requests[apiv1.ResourceCPU]).To(gomega.Equal(ParseQuantityOrDie("250m")))
951-
gomega.Expect(pod.Spec.Containers[0].Resources.Requests[apiv1.ResourceMemory]).To(gomega.Equal(ParseQuantityOrDie("200Mi")))
952-
}
953-
})
954962
})
955963

956964
func startDeploymentPods(f *framework.Framework, deployment *appsv1.Deployment) *apiv1.PodList {

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

+14-17
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,35 @@ var hamsterTargetRef = &autoscaling.CrossVersionObjectReference{
7575
var hamsterLabels = map[string]string{"app": "hamster"}
7676

7777
// SIGDescribe adds sig-autoscaling tag to test description.
78-
func SIGDescribe(text string, body func()) bool {
79-
return ginkgo.Describe(fmt.Sprintf("[sig-autoscaling] %v", text), body)
80-
}
81-
82-
// E2eDescribe describes a VPA e2e test.
83-
func E2eDescribe(scenario, name string, body func()) bool {
84-
return SIGDescribe(fmt.Sprintf("[VPA] [%s] [v1] %s", scenario, name), body)
78+
// Takes args that are passed to ginkgo.Describe.
79+
func SIGDescribe(scenario, name string, args ...interface{}) bool {
80+
full := fmt.Sprintf("[sig-autoscaling] [VPA] [%s] [v1] %s", scenario, name)
81+
return ginkgo.Describe(full, args...)
8582
}
8683

8784
// RecommenderE2eDescribe describes a VPA recommender e2e test.
88-
func RecommenderE2eDescribe(name string, body func()) bool {
89-
return E2eDescribe(recommenderComponent, name, body)
85+
func RecommenderE2eDescribe(name string, args ...interface{}) bool {
86+
return SIGDescribe(recommenderComponent, name, args...)
9087
}
9188

9289
// UpdaterE2eDescribe describes a VPA updater e2e test.
93-
func UpdaterE2eDescribe(name string, body func()) bool {
94-
return E2eDescribe(updateComponent, name, body)
90+
func UpdaterE2eDescribe(name string, args ...interface{}) bool {
91+
return SIGDescribe(updateComponent, name, args...)
9592
}
9693

9794
// AdmissionControllerE2eDescribe describes a VPA admission controller e2e test.
98-
func AdmissionControllerE2eDescribe(name string, body func()) bool {
99-
return E2eDescribe(admissionControllerComponent, name, body)
95+
func AdmissionControllerE2eDescribe(name string, args ...interface{}) bool {
96+
return SIGDescribe(admissionControllerComponent, name, args...)
10097
}
10198

10299
// FullVpaE2eDescribe describes a VPA full stack e2e test.
103-
func FullVpaE2eDescribe(name string, body func()) bool {
104-
return E2eDescribe(fullVpaSuite, name, body)
100+
func FullVpaE2eDescribe(name string, args ...interface{}) bool {
101+
return SIGDescribe(fullVpaSuite, name, args...)
105102
}
106103

107104
// ActuationSuiteE2eDescribe describes a VPA actuation e2e test.
108-
func ActuationSuiteE2eDescribe(name string, body func()) bool {
109-
return E2eDescribe(actuationSuite, name, body)
105+
func ActuationSuiteE2eDescribe(name string, args ...interface{}) bool {
106+
return SIGDescribe(actuationSuite, name, args...)
110107
}
111108

112109
// GetHamsterContainerNameByIndex returns name of i-th hamster container.

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ var _ = FullVpaE2eDescribe("Pods under VPA", func() {
6161
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
6262
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
6363

64-
ginkgo.Describe("with InPlaceOrRecreate update mode [InPlaceOrRecreate]", ginkgo.Ordered, func() {
65-
ginkgo.BeforeAll(func() {
64+
ginkgo.Describe("with InPlaceOrRecreate update mode", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
65+
ginkgo.BeforeEach(func() {
6666
checkInPlaceOrRecreateTestsEnabled(f, true, false)
67-
})
6867

69-
ginkgo.BeforeEach(func() {
7068
ns := f.Namespace.Name
7169
ginkgo.By("Setting up a hamster deployment")
7270
rc = NewDynamicResourceConsumer("hamster", ns, KindDeployment,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
140140
})
141141
})
142142

143-
var _ = UpdaterE2eDescribe("Updater [InPlaceOrRecreate]", func() {
143+
var _ = UpdaterE2eDescribe("Updater", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
144144
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
145145
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
146146

0 commit comments

Comments
 (0)