Skip to content

Commit 06db22e

Browse files
committed
Switch e2e tests with feature flag to use framework.WithFeatureGate
At the moment our e2e coverage for feature flags (default to off) isn't great. My thinking is to copy k/k and have 2 sets of jobs that execute: 1. e2e tests that exclude tests that have their feature gates set to disabled by default 2. e2e tests that include tests that require their featute gates to be enabled I plan to do this using gingko labels. WithFeatureGate adds a label `Feature:OffByDefault` which we can use to ignore or include, depending on which e2e test job is running.
1 parent f197832 commit 06db22e

File tree

4 files changed

+41
-45
lines changed

4 files changed

+41
-45
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import (
2525

2626
apiv1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
utilfeature "k8s.io/apiserver/pkg/util/feature"
2829
"k8s.io/autoscaler/vertical-pod-autoscaler/e2e/utils"
2930
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
31+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
3032
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3133
"k8s.io/kubernetes/test/e2e/framework"
3234
podsecurity "k8s.io/pod-security-admission/api"
@@ -35,20 +37,28 @@ import (
3537
"github.com/onsi/gomega"
3638
)
3739

40+
func init() {
41+
// Dynamically register feature gates from the VPA's versioned feature gate configuration
42+
// This ensures consistency with the main VPA feature gate definitions
43+
if err := utilfeature.DefaultMutableFeatureGate.Add(features.MutableFeatureGate.GetAll()); err != nil {
44+
panic(fmt.Sprintf("Failed to add VPA feature gates: %v", err))
45+
}
46+
}
47+
3848
const (
3949
webhookConfigName = "vpa-webhook-config"
4050
webhookName = "vpa.k8s.io"
4151
)
4252

43-
var _ = AdmissionControllerE2eDescribe("Admission-controller", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
53+
var _ = AdmissionControllerE2eDescribe("Admission-controller", func() {
4454
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
4555
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
4656

4757
ginkgo.BeforeEach(func() {
4858
waitForVpaWebhookRegistration(f)
4959
})
5060

51-
ginkgo.It("starts pods with new recommended request with InPlaceOrRecreate mode", func() {
61+
f.It("starts pods with new recommended request with InPlaceOrRecreate mode", framework.WithFeatureGate(features.InPlaceOrRecreate), func() {
5262
d := NewHamsterDeploymentWithResources(f, ParseQuantityOrDie("100m") /*cpu*/, ParseQuantityOrDie("100Mi") /*memory*/)
5363

5464
ginkgo.By("Setting up a VPA CRD")

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"strings"
2423
"time"
2524

2625
ginkgo "github.com/onsi/ginkgo/v2"
@@ -37,7 +36,6 @@ import (
3736
"k8s.io/autoscaler/vertical-pod-autoscaler/e2e/utils"
3837
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
3938
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
40-
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
4139
clientset "k8s.io/client-go/kubernetes"
4240
"k8s.io/kubernetes/test/e2e/framework"
4341
framework_deployment "k8s.io/kubernetes/test/e2e/framework/deployment"
@@ -468,26 +466,3 @@ func WaitForPodsUpdatedWithoutEviction(f *framework.Framework, initialPods *apiv
468466
framework.Logf("finished waiting for at least one pod to be updated without eviction")
469467
return err
470468
}
471-
472-
// checkPerVPAConfigTestsEnabled checks if the PerVPAConfig feature gate is enabled
473-
// in the VPA recommender.
474-
func checkPerVPAConfigTestsEnabled(f *framework.Framework) {
475-
ginkgo.By("Checking PerVPAConfig feature gate is enabled for recommender")
476-
deploy, err := f.ClientSet.AppsV1().Deployments(VpaNamespace).Get(context.TODO(), "vpa-recommender", metav1.GetOptions{})
477-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
478-
gomega.Expect(deploy.Spec.Template.Spec.Containers).To(gomega.HaveLen(1))
479-
vpaRecommenderPod := deploy.Spec.Template.Spec.Containers[0]
480-
gomega.Expect(vpaRecommenderPod.Name).To(gomega.Equal("recommender"))
481-
if !anyContainsSubstring(vpaRecommenderPod.Args, fmt.Sprintf("%s=true", string(features.PerVPAConfig))) {
482-
ginkgo.Skip("Skipping suite: PerVPAConfig feature gate is not enabled for the VPA recommender")
483-
}
484-
}
485-
486-
func anyContainsSubstring(arr []string, substr string) bool {
487-
for _, s := range arr {
488-
if strings.Contains(s, substr) {
489-
return true
490-
}
491-
}
492-
return false
493-
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import (
2626
"k8s.io/apimachinery/pkg/api/resource"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/util/wait"
29+
utilfeature "k8s.io/apiserver/pkg/util/feature"
2930
"k8s.io/autoscaler/vertical-pod-autoscaler/e2e/utils"
3031
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
32+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
3133
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3234
"k8s.io/kubernetes/test/e2e/framework"
3335
podsecurity "k8s.io/pod-security-admission/api"
@@ -47,6 +49,14 @@ const (
4749
oomTestTimeout = 8 * time.Minute
4850
)
4951

52+
func init() {
53+
// Dynamically register feature gates from the VPA's versioned feature gate configuration
54+
// This ensures consistency with the main VPA feature gate definitions
55+
if err := utilfeature.DefaultMutableFeatureGate.Add(features.MutableFeatureGate.GetAll()); err != nil {
56+
panic(fmt.Sprintf("Failed to add VPA feature gates: %v", err))
57+
}
58+
}
59+
5060
var _ = FullVpaE2eDescribe("Pods under VPA", func() {
5161
var (
5262
rc *ResourceConsumer
@@ -62,7 +72,7 @@ var _ = FullVpaE2eDescribe("Pods under VPA", func() {
6272
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
6373
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
6474

65-
ginkgo.Describe("with InPlaceOrRecreate update mode", ginkgo.Label("FG:InPlaceOrRecreate"), func() {
75+
f.Describe("with InPlaceOrRecreate update mode", framework.WithFeatureGate(features.InPlaceOrRecreate), func() {
6676
ginkgo.BeforeEach(func() {
6777
ns := f.Namespace.Name
6878
ginkgo.By("Setting up a hamster deployment")

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ import (
2929
"k8s.io/apimachinery/pkg/api/resource"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/fields"
32+
utilfeature "k8s.io/apiserver/pkg/util/feature"
3233
"k8s.io/autoscaler/vertical-pod-autoscaler/e2e/utils"
3334
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
3435
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
36+
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
3537
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/model"
3638
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3739
clientset "k8s.io/client-go/kubernetes"
@@ -41,6 +43,14 @@ import (
4143
podsecurity "k8s.io/pod-security-admission/api"
4244
)
4345

46+
func init() {
47+
// Dynamically register feature gates from the VPA's versioned feature gate configuration
48+
// This ensures consistency with the main VPA feature gate definitions
49+
if err := utilfeature.DefaultMutableFeatureGate.Add(features.MutableFeatureGate.GetAll()); err != nil {
50+
panic(fmt.Sprintf("Failed to add VPA feature gates: %v", err))
51+
}
52+
}
53+
4454
type resourceRecommendation struct {
4555
target, lower, upper int64
4656
}
@@ -51,7 +61,6 @@ func (r *resourceRecommendation) sub(other *resourceRecommendation) resourceReco
5161
lower: r.lower - other.lower,
5262
upper: r.upper - other.upper,
5363
}
54-
5564
}
5665

5766
func getResourceRecommendation(containerRecommendation *vpa_types.RecommendedContainerResources, r apiv1.ResourceName) resourceRecommendation {
@@ -411,45 +420,37 @@ var _ = utils.RecommenderE2eDescribe("VPA CRD object", func() {
411420
gomega.Expect(vpa.Status.Recommendation.ContainerRecommendations).Should(gomega.HaveLen(1), errMsg)
412421
gomega.Expect(vpa.Status.Recommendation.ContainerRecommendations[0].ContainerName).To(gomega.Equal(utils.GetHamsterContainerNameByIndex(1)), errMsg)
413422
})
414-
})
423+
f.It("have memory requests growing with OOMs more than the default", framework.WithFeatureGate(features.PerVPAConfig), func() {
424+
const replicas = 1
425+
const defaultOOMBumpUpRatio = model.DefaultOOMBumpUpRatio
426+
const oomBumpUpRatio = 3
415427

416-
var _ = utils.RecommenderE2eDescribe("OOM with custom config", ginkgo.Label("FG:PerVPAConfig"), func() {
417-
const replicas = 1
418-
const defaultOOMBumpUpRatio = model.DefaultOOMBumpUpRatio
419-
const oomBumpUpRatio = 3
420-
f := framework.NewDefaultFramework("vertical-pod-autoscaling")
421-
f.NamespacePodSecurityEnforceLevel = podsecurity.LevelBaseline
422-
var (
423-
vpaCRD *vpa_types.VerticalPodAutoscaler
424-
vpaClientSet vpa_clientset.Interface
425-
)
426-
ginkgo.BeforeEach(func() {
427-
checkPerVPAConfigTestsEnabled(f)
428428
ns := f.Namespace.Name
429429
vpaClientSet = utils.GetVpaClientSet(f)
430+
430431
ginkgo.By("Setting up a hamster deployment")
431432
runOomingReplicationController(
432433
f.ClientSet,
433434
ns,
434435
"hamster",
435436
replicas)
437+
436438
ginkgo.By("Setting up a VPA CRD")
437439
targetRef := &autoscaling.CrossVersionObjectReference{
438440
APIVersion: "v1",
439441
Kind: "Deployment",
440442
Name: "hamster",
441443
}
442444
containerName := utils.GetHamsterContainerNameByIndex(0)
443-
vpaCRD = test.VerticalPodAutoscaler().
445+
vpaCRD := test.VerticalPodAutoscaler().
444446
WithName("hamster-vpa").
445447
WithNamespace(f.Namespace.Name).
446448
WithTargetRef(targetRef).
447449
WithContainer(containerName).
448450
WithOOMBumpUpRatio(resource.NewQuantity(oomBumpUpRatio, resource.DecimalSI)).
449451
Get()
450452
utils.InstallVPA(f, vpaCRD)
451-
})
452-
ginkgo.It("have memory requests growing with OOMs more than the default", func() {
453+
453454
ginkgo.By("Waiting for recommendation to be filled")
454455
vpa, err := utils.WaitForRecommendationPresent(vpaClientSet, vpaCRD)
455456
gomega.Expect(err).NotTo(gomega.HaveOccurred())

0 commit comments

Comments
 (0)