Skip to content

Commit ca83c17

Browse files
AryanBagademaxcao13
authored andcommitted
UPSTREAM: 8778: VPA: Allow e2e tests to reference a custom namespace
VPA: Allow e2e tests to reference a custom namespace (kubernetes#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 kubernetes#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 kubernetes#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 Signed-off-by: Max Cao <[email protected]>
1 parent 19fac01 commit ca83c17

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
@@ -221,7 +221,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
221221
func CreateAuthReaderRoleBinding(f *framework.Framework, namespace string) {
222222
ginkgo.By("Create role binding to let webhook read extension-apiserver-authentication")
223223
client := f.ClientSet
224-
_, err := client.RbacV1().RoleBindings("kube-system").Create(context.TODO(), &rbacv1.RoleBinding{
224+
_, err := client.RbacV1().RoleBindings(VpaNamespace).Create(context.TODO(), &rbacv1.RoleBinding{
225225
ObjectMeta: metav1.ObjectMeta{
226226
Name: roleBindingName,
227227
Annotations: map[string]string{
@@ -384,5 +384,5 @@ func CleanWebhookTest(client clientset.Interface, namespaceName string) {
384384
_ = client.CoreV1().Services(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
385385
_ = client.AppsV1().Deployments(namespaceName).Delete(context.TODO(), deploymentName, metav1.DeleteOptions{})
386386
_ = client.CoreV1().Secrets(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
387-
_ = client.RbacV1().RoleBindings("kube-system").Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
387+
_ = client.RbacV1().RoleBindings(VpaNamespace).Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
388388
}

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

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

6259
// 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
@@ -413,7 +413,7 @@ var _ = utils.RecommenderE2eDescribe("VPA CRD object", func() {
413413
})
414414

415415
func deleteRecommender(c clientset.Interface) error {
416-
namespace := "kube-system"
416+
namespace := utils.VpaNamespace
417417
listOptions := metav1.ListOptions{}
418418
podList, err := c.CoreV1().Pods(namespace).List(context.TODO(), listOptions)
419419
if err != nil {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
4747
statusUpdater := status.NewUpdater(
4848
f.ClientSet,
4949
status.AdmissionControllerStatusName,
50-
status.AdmissionControllerStatusNamespace,
50+
utils.VpaNamespace,
5151
statusUpdateInterval,
5252
"e2e test",
5353
)
@@ -56,7 +56,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
5656
// Status is created outside the test namespace.
5757
ginkgo.By("Deleting the Admission Controller status")
5858
close(stopCh)
59-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
59+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
6060
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
6161
gomega.Expect(err).NotTo(gomega.HaveOccurred())
6262
}()
@@ -77,7 +77,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
7777
statusUpdater := status.NewUpdater(
7878
f.ClientSet,
7979
status.AdmissionControllerStatusName,
80-
status.AdmissionControllerStatusNamespace,
80+
utils.VpaNamespace,
8181
statusUpdateInterval,
8282
"e2e test",
8383
)
@@ -86,7 +86,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
8686
// Status is created outside the test namespace.
8787
ginkgo.By("Deleting the Admission Controller status")
8888
close(stopCh)
89-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
89+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
9090
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
9191
gomega.Expect(err).NotTo(gomega.HaveOccurred())
9292
}()
@@ -107,7 +107,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
107107
statusUpdater := status.NewUpdater(
108108
f.ClientSet,
109109
status.AdmissionControllerStatusName,
110-
status.AdmissionControllerStatusNamespace,
110+
utils.VpaNamespace,
111111
statusUpdateInterval,
112112
"e2e test",
113113
)
@@ -116,7 +116,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
116116
// Status is created outside the test namespace.
117117
ginkgo.By("Deleting the Admission Controller status")
118118
close(stopCh)
119-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
119+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
120120
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
121121
gomega.Expect(err).NotTo(gomega.HaveOccurred())
122122
}()
@@ -148,7 +148,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
148148
statusUpdater := status.NewUpdater(
149149
f.ClientSet,
150150
status.AdmissionControllerStatusName,
151-
status.AdmissionControllerStatusNamespace,
151+
utils.VpaNamespace,
152152
statusUpdateInterval,
153153
"e2e test",
154154
)
@@ -157,7 +157,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
157157
// Status is created outside the test namespace.
158158
ginkgo.By("Deleting the Admission Controller status")
159159
close(stopCh)
160-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
160+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
161161
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
162162
gomega.Expect(err).NotTo(gomega.HaveOccurred())
163163
}()
@@ -179,7 +179,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
179179
statusUpdater := status.NewUpdater(
180180
f.ClientSet,
181181
status.AdmissionControllerStatusName,
182-
status.AdmissionControllerStatusNamespace,
182+
utils.VpaNamespace,
183183
statusUpdateInterval,
184184
"e2e test",
185185
)
@@ -188,7 +188,7 @@ var _ = UpdaterE2eDescribe("Updater", func() {
188188
// Status is created outside the test namespace.
189189
ginkgo.By("Deleting the Admission Controller status")
190190
close(stopCh)
191-
err := f.ClientSet.CoordinationV1().Leases(status.AdmissionControllerStatusNamespace).
191+
err := f.ClientSet.CoordinationV1().Leases(utils.VpaNamespace).
192192
Delete(context.TODO(), status.AdmissionControllerStatusName, metav1.DeleteOptions{})
193193
gomega.Expect(err).NotTo(gomega.HaveOccurred())
194194
}()

0 commit comments

Comments
 (0)