Skip to content

Conversation

@AryanBagade
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Enables 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 makes the e2e tests consistent with the VPA components' ability to run in custom namespaces, as mentioned in issue #8752.

Which issue(s) this PR fixes:

Fixes #8752

Special notes for your reviewer:

This implementation follows the same pattern as PR #7654, using environment variables with sensible defaults to enable custom configurations without breaking existing tests.

The changes are minimal and only affect e2e test code:

  • Made VpaNamespace (e2e/v1/common.go) configurable via VPA_NAMESPACE env var
  • Made RecommenderNamespace (e2e/utils/common.go) configurable via VPA_NAMESPACE env var
  • Replaced hardcoded kube-system strings in deleteRecommender() function
  • Replaced hardcoded kube-system strings in webhook RoleBinding operations

All unit tests pass with race detection enabled.

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 9, 2025
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @AryanBagade!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 9, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @AryanBagade. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added area/vertical-pod-autoscaler size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/needs-area cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 9, 2025
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.
@AryanBagade AryanBagade force-pushed the feature/8752-vpa-e2e-custom-namespace branch from 6bf0cee to 90f51c8 Compare November 9, 2025 20:15
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Nov 9, 2025
@AryanBagade
Copy link
Contributor Author

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 9, 2025
@adrianmoisey
Copy link
Member

Thanks for doing this!

/ok-to-test
/cc @maxcao13

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 10, 2025
Copy link
Member

@omerap12 omerap12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the idea was to do something similar to this:
https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/hack/dev-deploy-locally.sh#L60

(i.e. set the variable names during the binary compilation step)

)

func init() {
if ns := os.Getenv("VPA_NAMESPACE"); ns != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is no VPA_NAMESPACE env variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the VPA_NAMESPACE environment variable is not set, os.Getenv("VPA_NAMESPACE") returns an empty string, so the condition ns != "" evaluates to false, and we don't override the default value. This means VpaNamespace and RecommenderNamespace remain as "kube-system", maintaining full backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I missed the VpaNamespace = "kube-system" above. thanks!

@AryanBagade
Copy link
Contributor Author

I thought the idea was to do something similar to this:

I chose runtime environment variables

  1. E2e tests benefit from runtime flexibility as you can run the same compiled test against different namespace configurations without recompiling
  2. This matches the pattern used by other e2e test configuration (like KUBECONFIG, TEST_WITH_FEATURE_GATES_ENABLED, etc.)
  3. It's simpler for developers like just set `VPA_NAMESPACE=custom-ns go test ./e2e/...

But if you prefer the build-time approach, I'm happy to adjust! What do you think?

Comment on lines -47 to -48
// RecommenderNamespace is namespace to deploy VPA recommender
RecommenderNamespace = "kube-system"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should just remove this variable and use VpaNamespace for everything if that's possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Sounds good!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm having two separate variables is redundant since they both serve the same purpose.
The change would be:

  • Keep the variable and init() function in e2e/utils/common.go
  • Rename RecommenderNamespaceVpaNamespace
  • Remove the duplicate from e2e/v1/common.go
  • Use utils.VpaNamespace everywhere

Does that sound good? Any other changes i need to make ????

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that makes sense to me. Thanks for doing this :-)

@maxcao13
Copy link
Member

maxcao13 commented Nov 10, 2025

I also think we need to configure these references too:

ginkgo.By("Setting up the Admission Controller status")
stopCh := make(chan struct{})
statusUpdater := status.NewUpdater(
f.ClientSet,
status.AdmissionControllerStatusName,
status.AdmissionControllerStatusNamespace,
statusUpdateInterval,
"e2e test",
)

Right now they will always point to kube-system.

status.AdmissionControllerStatusNamespace

@AryanBagade
Copy link
Contributor Author

right, I missed those references. Let me update those as well.

@maxcao13
Copy link
Member

I chose runtime environment variables

E2e tests benefit from runtime flexibility as you can run the same compiled test against different namespace configurations without recompiling
This matches the pattern used by other e2e test configuration (like KUBECONFIG, TEST_WITH_FEATURE_GATES_ENABLED, etc.)
It's simpler for developers like just set `VPA_NAMESPACE=custom-ns go test ./e2e/...

But if you prefer the build-time approach, I'm happy to adjust! What do you think?

+1 for me. it follows the other test configurations we've already been using.

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
@maxcao13
Copy link
Member

/lgtm

Thanks for the contribution!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 11, 2025
@omerap12
Copy link
Member

I thought the idea was to do something similar to this:

I chose runtime environment variables

  1. E2e tests benefit from runtime flexibility as you can run the same compiled test against different namespace configurations without recompiling
  2. This matches the pattern used by other e2e test configuration (like KUBECONFIG, TEST_WITH_FEATURE_GATES_ENABLED, etc.)
  3. It's simpler for developers like just set `VPA_NAMESPACE=custom-ns go test ./e2e/...

But if you prefer the build-time approach, I'm happy to adjust! What do you think?

Seems reasonable to me. I agree :)

Copy link
Member

@omerap12 omerap12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
/label tide/merge-method-squash
/approve

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 11, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AryanBagade, omerap12

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 11, 2025
@k8s-ci-robot k8s-ci-robot merged commit 7fe519c into kubernetes:master Nov 11, 2025
13 checks passed
maxcao13 pushed a commit to maxcao13/autoscaler that referenced this pull request Nov 11, 2025
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]>
cloud-team-bot bot pushed a commit to openshift-cloud-team/kubernetes-autoscaler that referenced this pull request Nov 13, 2025
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]>
cloud-team-bot bot pushed a commit to openshift-cloud-team/kubernetes-autoscaler that referenced this pull request Nov 20, 2025
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]>
jonkerj pushed a commit to equinix-ms/k8s-autoscaler that referenced this pull request Nov 24, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow VPA e2e tests to reference a custom namespace

5 participants