Skip to content

Commit 7fe519c

Browse files
authored
VPA: Allow e2e tests to reference a custom namespace (#8778)
* VPA: Allow e2e tests to reference a custom namespace Enable VPA e2e tests to use a custom namespace via the VPA_NAMESPACE environment variable, while maintaining backward compatibility with the default kube-system namespace. This addresses issue #8752 by making the e2e tests consistent with the VPA components' ability to run in custom namespaces. Changes: - Made VpaNamespace (e2e/v1/common.go) configurable via environment variable - Made RecommenderNamespace (e2e/utils/common.go) configurable via environment variable - Replaced hardcoded kube-system in deleteRecommender() function - Replaced hardcoded kube-system in webhook RoleBinding operations The implementation follows the same pattern as PR #7654, using environment variables with sensible defaults to enable custom configurations without breaking existing tests. * VPA: Allow e2e tests to reference a custom namespace Changes: - Consolidated to single VpaNamespace variable in e2e/utils/common.go - Added VPA_NAMESPACE environment variable support with init() function - Replaced all hardcoded namespace references in e2e tests: - e2e/v1/recommender.go deleteRecommender() function (1 instance) - e2e/v1/updater.go status namespace references (10 instances) - e2e/integration/recommender.go deployment operations (3 instances) - e2e/utils/webhook.go RoleBinding operations (2 instances) - Removed duplicate VpaNamespac from e2e/v1/common.go
1 parent 92cae79 commit 7fe519c

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ var _ = utils.RecommenderE2eDescribe("Flags", func() {
4646
})
4747

4848
ginkgo.AfterEach(func() {
49-
f.ClientSet.AppsV1().Deployments(utils.RecommenderNamespace).Delete(context.TODO(), utils.RecommenderDeploymentName, metav1.DeleteOptions{})
49+
f.ClientSet.AppsV1().Deployments(utils.VpaNamespace).Delete(context.TODO(), utils.RecommenderDeploymentName, metav1.DeleteOptions{})
5050
})
5151

5252
ginkgo.It("starts recommender with --vpa-object-namespace parameter", func() {
5353
ginkgo.By("Setting up VPA deployment")
5454
ignoredNamespace, err := f.CreateNamespace(context.TODO(), "ignored-namespace", nil)
5555
gomega.Expect(err).NotTo(gomega.HaveOccurred())
5656

57-
f.Namespace.Name = utils.RecommenderNamespace
57+
f.Namespace.Name = utils.VpaNamespace
5858
vpaDeployment := utils.NewVPADeployment(f, []string{
5959
"--recommender-interval=10s",
6060
fmt.Sprintf("--vpa-object-namespace=%s", hamsterNamespace),
@@ -69,7 +69,7 @@ var _ = utils.RecommenderE2eDescribe("Flags", func() {
6969
ignoredNamespace, err := f.CreateNamespace(context.TODO(), "ignored-namespace", nil)
7070
gomega.Expect(err).NotTo(gomega.HaveOccurred())
7171

72-
f.Namespace.Name = utils.RecommenderNamespace
72+
f.Namespace.Name = utils.VpaNamespace
7373
vpaDeployment := utils.NewVPADeployment(f, []string{
7474
"--recommender-interval=10s",
7575
fmt.Sprintf("--ignored-vpa-object-namespaces=%s", ignoredNamespace.Name),

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"os"
2324
"time"
2425

2526
ginkgo "github.com/onsi/ginkgo/v2"
@@ -44,8 +45,6 @@ const (
4445

4546
// RecommenderDeploymentName is VPA recommender deployment name
4647
RecommenderDeploymentName = "vpa-recommender"
47-
// RecommenderNamespace is namespace to deploy VPA recommender
48-
RecommenderNamespace = "kube-system"
4948
// PollInterval is interval for polling
5049
PollInterval = 10 * time.Second
5150
// PollTimeout is timeout for polling
@@ -57,6 +56,18 @@ const (
5756
DefaultHamsterBackoffLimit = int32(10)
5857
)
5958

59+
var (
60+
// VpaNamespace is namespace to deploy VPA components.
61+
// Can be overridden via VPA_NAMESPACE environment variable.
62+
VpaNamespace = "kube-system"
63+
)
64+
65+
func init() {
66+
if ns := os.Getenv("VPA_NAMESPACE"); ns != "" {
67+
VpaNamespace = ns
68+
}
69+
}
70+
6071
// HamsterTargetRef is CrossVersionObjectReference of hamster app
6172
var HamsterTargetRef = &autoscaling.CrossVersionObjectReference{
6273
APIVersion: "apps/v1",

vertical-pod-autoscaler/e2e/utils/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
219219
func CreateAuthReaderRoleBinding(f *framework.Framework, namespace string) {
220220
ginkgo.By("Create role binding to let webhook read extension-apiserver-authentication")
221221
client := f.ClientSet
222-
_, err := client.RbacV1().RoleBindings("kube-system").Create(context.TODO(), &rbacv1.RoleBinding{
222+
_, err := client.RbacV1().RoleBindings(VpaNamespace).Create(context.TODO(), &rbacv1.RoleBinding{
223223
ObjectMeta: metav1.ObjectMeta{
224224
Name: roleBindingName,
225225
Annotations: map[string]string{
@@ -382,5 +382,5 @@ func CleanWebhookTest(client clientset.Interface, namespaceName string) {
382382
_ = client.CoreV1().Services(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
383383
_ = client.AppsV1().Deployments(namespaceName).Delete(context.TODO(), deploymentName, metav1.DeleteOptions{})
384384
_ = client.CoreV1().Secrets(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
385-
_ = client.RbacV1().RoleBindings("kube-system").Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
385+
_ = client.RbacV1().RoleBindings(VpaNamespace).Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
386386
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ const (
5353
// VpaInPlaceTimeout is a timeout for the VPA to finish in-place resizing a
5454
// pod, if there are no mechanisms blocking it.
5555
VpaInPlaceTimeout = 2 * time.Minute
56-
57-
// VpaNamespace is the default namespace that holds the all the VPA components.
58-
VpaNamespace = "kube-system"
5956
)
6057

6158
// UpdaterE2eDescribe describes a VPA updater e2e test.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ var _ = utils.RecommenderE2eDescribe("VPA CRD object", func() {
480480
})
481481

482482
func deleteRecommender(c clientset.Interface) error {
483-
namespace := "kube-system"
483+
namespace := utils.VpaNamespace
484484
listOptions := metav1.ListOptions{}
485485
podList, err := c.CoreV1().Pods(namespace).List(context.TODO(), listOptions)
486486
if err != nil {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
4848
statusUpdater := status.NewUpdater(
4949
f.ClientSet,
5050
status.AdmissionControllerStatusName,
51-
status.AdmissionControllerStatusNamespace,
51+
utils.VpaNamespace,
5252
statusUpdateInterval,
5353
"e2e test",
5454
)
@@ -57,7 +57,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
5757
// Status is created outside the test namespace.
5858
ginkgo.By("Deleting the Admission Controller status")
5959
close(stopCh)
60-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
60+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
6161
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
6262
gomega.Expect(err).NotTo(gomega.HaveOccurred())
6363
}()
@@ -79,7 +79,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
7979
statusUpdater := status.NewUpdater(
8080
f.ClientSet,
8181
status.AdmissionControllerStatusName,
82-
status.AdmissionControllerStatusNamespace,
82+
utils.VpaNamespace,
8383
statusUpdateInterval,
8484
"e2e test",
8585
)
@@ -88,7 +88,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
8888
// Status is created outside the test namespace.
8989
ginkgo.By("Deleting the Admission Controller status")
9090
close(stopCh)
91-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
91+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
9292
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
9393
gomega.Expect(err).NotTo(gomega.HaveOccurred())
9494
}()
@@ -109,7 +109,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
109109
statusUpdater := status.NewUpdater(
110110
f.ClientSet,
111111
status.AdmissionControllerStatusName,
112-
status.AdmissionControllerStatusNamespace,
112+
utils.VpaNamespace,
113113
statusUpdateInterval,
114114
"e2e test",
115115
)
@@ -118,7 +118,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
118118
// Status is created outside the test namespace.
119119
ginkgo.By("Deleting the Admission Controller status")
120120
close(stopCh)
121-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
121+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
122122
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
123123
gomega.Expect(err).NotTo(gomega.HaveOccurred())
124124
}()
@@ -151,7 +151,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
151151
statusUpdater := status.NewUpdater(
152152
f.ClientSet,
153153
status.AdmissionControllerStatusName,
154-
status.AdmissionControllerStatusNamespace,
154+
utils.VpaNamespace,
155155
statusUpdateInterval,
156156
"e2e test",
157157
)
@@ -160,7 +160,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
160160
// Status is created outside the test namespace.
161161
ginkgo.By("Deleting the Admission Controller status")
162162
close(stopCh)
163-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
163+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
164164
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
165165
gomega.Expect(err).NotTo(gomega.HaveOccurred())
166166
}()
@@ -183,7 +183,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
183183
statusUpdater := status.NewUpdater(
184184
f.ClientSet,
185185
status.AdmissionControllerStatusName,
186-
status.AdmissionControllerStatusNamespace,
186+
utils.VpaNamespace,
187187
statusUpdateInterval,
188188
"e2e test",
189189
)
@@ -192,7 +192,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
192192
// Status is created outside the test namespace.
193193
ginkgo.By("Deleting the Admission Controller status")
194194
close(stopCh)
195-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
195+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
196196
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
197197
gomega.Expect(err).NotTo(gomega.HaveOccurred())
198198
}()

0 commit comments

Comments
 (0)