Skip to content
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

Feat: improve VPA filtering and checkpoint garbage collection #7716

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

Conversation

omerap12
Copy link
Member

@omerap12 omerap12 commented Jan 17, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

Currently, the recommender's garbage collection for checkpoints iterates through all namespaces in the cluster, ignoring the vpaObjectNamespace and ignoredNamespaces flags. In large-scale clusters, this can lead to performance issues. This PR addresses the problem by ensuring that the garbage collection logic respects the specified flags.

Which issue(s) this PR fixes:

Fixes #7697

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixes VPA recommender garbage collection to respect `vpaObjectNamespace` and `ignoredNamespaces` flags, improving performance in large-scale clusters by limiting the scope of namespace checks.

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

Change flags description

@k8s-ci-robot
Copy link
Contributor

@omerap12: The label(s) kind/featrue cannot be applied, because the repository doesn't have them.

In response to this:

What type of PR is this?

/kind featrue

What this PR does / why we need it:

Currently, the recommender's garbage collection for checkpoints iterates through all namespaces in the cluster, ignoring the vpaObjectNamespace and ignoredNamespaces flags. In large-scale clusters, this can lead to performance issues. This PR addresses the problem by ensuring that the garbage collection logic respects the specified flags.

Which issue(s) this PR fixes:

Fixes #7697

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixes VPA recommender garbage collection to respect `vpaObjectNamespace` and `ignoredNamespaces` flags, improving performance in large-scale clusters by limiting the scope of namespace checks.

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

Not sure where should I document this change

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 17, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: omerap12
Once this PR has been reviewed and has the lgtm label, please assign kgolab 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 requested a review from voelzmo January 17, 2025 12:31
@omerap12
Copy link
Member Author

/kind feature

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 17, 2025
@adrianmoisey
Copy link
Member

Not sure where should I document this change

I'm not sure if this is a good idea, but what about updating the flags:

flag.StringVar(&cf.VpaObjectNamespace, "vpa-object-namespace", apiv1.NamespaceAll, "Namespace to search for VPA objects. Empty means all namespaces will be used.")
flag.StringVar(&cf.IgnoredVpaObjectNamespaces, "ignored-vpa-object-namespaces", "", "Comma separated list of namespaces to ignore when searching for VPA objects. Empty means no namespaces will be ignored.")
?

@omerap12 omerap12 force-pushed the recommender-namespaces branch from 90cb7a6 to 85370c3 Compare January 17, 2025 20:22
@omerap12
Copy link
Member Author

Not sure where should I document this change

I'm not sure if this is a good idea, but what about updating the flags:

flag.StringVar(&cf.VpaObjectNamespace, "vpa-object-namespace", apiv1.NamespaceAll, "Namespace to search for VPA objects. Empty means all namespaces will be used.")
flag.StringVar(&cf.IgnoredVpaObjectNamespaces, "ignored-vpa-object-namespaces", "", "Comma separated list of namespaces to ignore when searching for VPA objects. Empty means no namespaces will be ignored.")

?

sounds good

@omerap12 omerap12 force-pushed the recommender-namespaces branch from 1e1fc7a to 8117b14 Compare January 19, 2025 08:29
@adrianmoisey
Copy link
Member

/lgtm

Thanks!

If you're up for it, an e2e test testing the flag would be cool, but I know we have an item in the backlog for that already.

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 19, 2025
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 21, 2025
Signed-off-by: Omer Aplatony <[email protected]>
@omerap12
Copy link
Member Author

Had to rebase so pinging again @adrianmoisey

@adrianmoisey
Copy link
Member

/lgtm

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

/milestone vertical-pod-autoscaler-1.4.0

Copy link
Contributor

@voelzmo voelzmo 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 the PR, I have some comments where code could be a bit simpler.

return feeder.vpaObjectNamespace == "" && len(feeder.ignoredNamespaces) == 0
}

func (feeder *clusterStateFeeder) cleanupCheckpointsForNamespace(namespace string, allVPAKeys map[model.VpaID]bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can make this function return err and have the caller handle it. This way, you can also simplify the if-else and the error messages, as they don't need to contain the context that this happened inside the garbage collection function. Adding context for the checkpoint listing with e.g. errors.Wrapf could still be useful, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 86eb551

@@ -354,7 +382,7 @@ func filterVPAs(feeder *clusterStateFeeder, allVpaCRDs []*vpa_types.VerticalPodA
}
}

if slices.Contains(feeder.ignoredNamespaces, vpaCRD.ObjectMeta.Namespace) {
if !feeder.shouldCleanupNamespace(vpaCRD.ObjectMeta.Namespace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're re-using shouldCleanupNamespace here, I think we should rename it. Currently, its name is tied pretty much to the garbage collection use-case. Maybe it is rather something like shouldIgnoreNamespace?

On the other hand, we already initialize the vpaLister with a single namespace if vpaObjectNamespace is set:

VpaLister: vpa_api_util.NewVpasLister(vpa_clientset.NewForConfigOrDie(config), make(chan struct{}), commonFlag.VpaObjectNamespace),
so we probably don't need to do this here and filtering for the ignored namespaces is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose we can keep using slices.Contains as it was, but personally, I’m not a fan of duplicated code (since shouldCleanupNamespace does the same thing).

Do you have a preference? Should we rename the function, or are we okay with some duplication?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with renaming the method and reduce duplication. We could also re-use the same method then for filtering the VPACheckpoints returned by the lister introduced in #6419

Copy link
Member Author

Choose a reason for hiding this comment

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

no problem

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 694cce8

Signed-off-by: Omer Aplatony <[email protected]>
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 31, 2025
Signed-off-by: Omer Aplatony <[email protected]>
Signed-off-by: Omer Aplatony <[email protected]>
@omerap12 omerap12 force-pushed the recommender-namespaces branch from 13fb008 to 694cce8 Compare February 4, 2025 20:26
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/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restricting VPA recommender scans to specific namespaces
4 participants