Skip to content

chore: add recommender vpa-object-namespace integration test #8348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

phuhung273
Copy link

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

  • Integration test for recommender flags: vpa-object-namespace, ignored-vpa-object-namespaces
  • Moving some functions from e2e/v1 to e2e/utils for usage across integration and v1. Please let me know if this is appropriate.

Which issue(s) this PR fixes:

Relates #7723

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area area/vertical-pod-autoscaler needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 23, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @phuhung273. Thanks for your PR.

I'm waiting for a kubernetes 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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: phuhung273
Once this PR has been reviewed and has the lgtm label, please assign raywainman for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 23, 2025
@phuhung273 phuhung273 force-pushed the vpa-recommender-namespace-test branch 2 times, most recently from 038a8b6 to b123353 Compare July 23, 2025 13:58
@omerap12
Copy link
Member

/ok-to-test

@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 Jul 23, 2025
@adrianmoisey
Copy link
Member

  • Integration test for recommender flags: vpa-object-namespace, ignored-vpa-object-namespaces
  • Moving some functions from e2e/v1 to e2e/utils for usage across integration and v1. Please let me know if this is appropriate.

Hey

Would it be possible to split this PR into multiple commits for easier review?

@phuhung273
Copy link
Author

Sure @adrianmoisey, im thinking about:

  • 1 commit only for moving functions from v1 -> utils
  • 1 commit for new tests

How do you think ?

@adrianmoisey
Copy link
Member

Sounds good to me

@phuhung273 phuhung273 force-pushed the vpa-recommender-namespace-test branch from b123353 to 656d363 Compare July 29, 2025 12:44
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 29, 2025
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 29, 2025
@phuhung273
Copy link
Author

I've splitted into 2 commits. Please help take a look @adrianmoisey. Thanks

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.

Couple of comments from my side. regarding the integration tests only

// Run a test container to try and contact the Kubernetes api-server from a pod, wait for it
// to flip to Ready, log its output and delete it.
func runKubernetesServiceTestContainer(c clientset.Interface, ns string) {
path := "test/images/clusterapi-tester/pod.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

what is this path?

Copy link
Author

@phuhung273 phuhung273 Aug 5, 2025

Choose a reason for hiding this comment

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

I have no idea actually... This file was copied from e2e/v1. Should I also move these functions to utils ?

cc @adrianmoisey

Copy link
Member

Choose a reason for hiding this comment

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

What was the reason for copying it, rather than reusing it?

Copy link
Author

Choose a reason for hiding this comment

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

No reason, I forgot this file at first 😅 Sorry for this.

IMO, we should reuse it.

By reusing, i mean moving it to utils. We cannot just making it public as importing e2e/v1 will trigger all tests.


// Run a test container to try and contact the Kubernetes api-server from a pod, wait for it
// to flip to Ready, log its output and delete it.
func runKubernetesServiceTestContainer(c clientset.Interface, ns string) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we need this test. can you please elaborate?

Copy link
Author

Choose a reason for hiding this comment

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

This file was copied from e2e/v1. Can we discuss in #8348 (comment) ?

Comment on lines 42 to 47
if framework.TestContext.ListImages {
for _, v := range image.GetImageConfigs() {
fmt.Println(v.GetE2EImage())
}
os.Exit(0)
}
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 not sure why this is here. Actually, I don't really understand what's happening in this whole file. Can you please explain?

Copy link
Author

Choose a reason for hiding this comment

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

I tried to remove this and the test still work. Will remove it.

About the whole file, I can confirm that we need TestMain and handleFlags since it will fail parsing params like --disable-log-dump in go test command https://github.com/phuhung273/autoscaler/blob/e90e2f377cb8ab74948e287817a79cb5636dff16/vertical-pod-autoscaler/hack/run-integration-locally.sh#L114

Copy link
Member

Choose a reason for hiding this comment

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

Understood. we can just remove this section then

})

ginkgo.AfterEach(func() {
f.ClientSet.AppsV1().Deployments(utils.RecommenderNamespace).Delete(context.TODO(), utils.RecommenderDeploymentName, metav1.DeleteOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to delete the namespaces we are creating in every test?
like we have in line 54:

ignoredNamespace, err := f.CreateNamespace(context.TODO(), "ignored-namespace", nil)

Copy link
Author

Choose a reason for hiding this comment

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

From what i've seen, namespaces created by f.CreateNamespace are automatically cleaned up after every test.

I added delete deployment here since VPA (kube-system) is not automatically cleaned.

Comment on lines +130 to +133
ginkgo.By("Ignored namespace should not be recommended")
ignoredVpa, err := vpaClientSet.AutoscalingV1().VerticalPodAutoscalers(ignoredNamespace).Get(context.TODO(), ignoredVpaCRD.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(ignoredVpa.Status.Conditions).Should(gomega.HaveLen(0))
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment explaining the logic of this test? It looks like you're creating two namespaces and two VPAs with the same targetRef. One VPA uses the --ignore-namespace flag, so it shouldn't generate any recommendations, while the other should. A short comment would help make this more understandable.

Copy link
Author

Choose a reason for hiding this comment

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

Yes your summary is correct. Two VPAs have the same targetRef but theyre in different namespaces.

I just added a comment to the function. Please let me know if it is clear enough. Thanks man.

@@ -145,6 +145,25 @@ func PatchVpaRecommendation(f *framework.Framework, vpa *vpa_types.VerticalPodAu
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to patch VPA.")
}

// NewVPADeployment creates a VPA deployment with n containers
// for e2e test purposes.
func NewVPADeployment(f *framework.Framework, flags []string) *appsv1.Deployment {
Copy link
Member

Choose a reason for hiding this comment

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

TODO (future PRs)- update this function to receive args as well

Copy link
Author

Choose a reason for hiding this comment

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

Absolutely, right now i have no special config.


vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
vpa_clientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
framework_deployment "k8s.io/kubernetes/test/e2e/framework/deployment"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this should be in the section above

Copy link
Author

Choose a reason for hiding this comment

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

Sure i've moved it to above section. Hope I understand your point correctly ?

Copy link
Member

Choose a reason for hiding this comment

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

This whole file already lives in e2e/v1/e2e.go with a few minor changes

Copy link
Author

Choose a reason for hiding this comment

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

Yes you're correct. Can we discuss in #8348 (comment) to also move functions in this file to utils ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants