Skip to content

Commit 6bf0cee

Browse files
committed
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. Fixes #8752
1 parent 6177945 commit 6bf0cee

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

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+
// RecommenderNamespace is namespace to deploy VPA recommender.
61+
// Can be overridden via VPA_NAMESPACE environment variable.
62+
RecommenderNamespace = "kube-system"
63+
)
64+
65+
func init() {
66+
if ns := os.Getenv("VPA_NAMESPACE"); ns != "" {
67+
RecommenderNamespace = 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(RecommenderNamespace).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(RecommenderNamespace).Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
386386
}

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

Lines changed: 11 additions & 1 deletion
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"
@@ -53,11 +54,20 @@ const (
5354
// VpaInPlaceTimeout is a timeout for the VPA to finish in-place resizing a
5455
// pod, if there are no mechanisms blocking it.
5556
VpaInPlaceTimeout = 2 * time.Minute
57+
)
5658

57-
// VpaNamespace is the default namespace that holds the all the VPA components.
59+
var (
60+
// VpaNamespace is the namespace that holds the all the VPA components.
61+
// Can be overridden via VPA_NAMESPACE environment variable.
5862
VpaNamespace = "kube-system"
5963
)
6064

65+
func init() {
66+
if ns := os.Getenv("VPA_NAMESPACE"); ns != "" {
67+
VpaNamespace = ns
68+
}
69+
}
70+
6171
// UpdaterE2eDescribe describes a VPA updater e2e test.
6272
func UpdaterE2eDescribe(name string, args ...interface{}) bool {
6373
return utils.SIGDescribe(updateComponent, name, args...)

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 := VpaNamespace
484484
listOptions := metav1.ListOptions{}
485485
podList, err := c.CoreV1().Pods(namespace).List(context.TODO(), listOptions)
486486
if err != nil {

0 commit comments

Comments
 (0)