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

Add namespace label selector #1501

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

RomanenkoDenys
Copy link

Added namespace label selector for filtering pods in the DefaultEvictor plugin.
This is useful when descheduler uses only, for example, in the stage or dev namespaces.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ingvagabund for approval. For more information see the Kubernetes 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 25, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @RomanenkoDenys!

It looks like this is your first PR to kubernetes-sigs/descheduler 🎉. 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-sigs/descheduler 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 25, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @RomanenkoDenys. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 25, 2024
@a7i
Copy link
Contributor

a7i commented Aug 29, 2024

/ok-to-test

would you please squash your commits?

@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 Aug 29, 2024
@a7i
Copy link
Contributor

a7i commented Aug 29, 2024

@RomanenkoDenys great feature! would you be open to adding an e2e test for this?

@@ -157,6 +159,25 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
})
}

// check pod by namespace label filter
if defaultEvictorArgs.NamespaceLabelSelector != nil {
Copy link
Contributor

@ingvagabund ingvagabund Aug 29, 2024

Choose a reason for hiding this comment

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

E.g. LowNodeUtilization plugin will not like it:

. The plugin needs to evaluate all the pods so it can properly compute the resource utilization. There's EvictableNamespaces complement field which matches the namespaces right before eviction. Putting the namespace filtering here would break the plugin's functionality. The same for HighNodeUtilization or any plugin that balances pods on the cluster scope.

This needs to go under PreEvictionFilter extension point. In the case of having each plugin to decide whether it wants to perform namespace filtering before balancing/descheduling pods the filtering needs to be added in each plugin's New function. Or in case namespaces are iterated explicitly in the corresponding methods (if it can not be done as part of pod filtering). E.g.

var includedNamespaces, excludedNamespaces sets.Set[string]
if d.args.Namespaces != nil {
includedNamespaces = sets.New(d.args.Namespaces.Include...)
excludedNamespaces = sets.New(d.args.Namespaces.Exclude...)
}
.

Copy link
Author

@RomanenkoDenys RomanenkoDenys Aug 30, 2024

Choose a reason for hiding this comment

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

Hi, I think you are right. But i have one question. In front of my code there is a constraint for podLabelSelector. And this selector theoretically does not allow to compute all pods, because we can label pods and remove them from the computation using pod label selector.

Icluding/excluding namespaces by name list is not acceptable for us, because in this case we cannot work with dynamically created namespaces (e.g. for dev environments). Using a label selector is our preferred method.

Copy link
Contributor

@ingvagabund ingvagabund Aug 30, 2024

Choose a reason for hiding this comment

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

Is this part of #1499? Or, is your PR a parallel/independent effort?

Copy link
Contributor

Choose a reason for hiding this comment

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

But i have one question.

Which question is it? I see only statements.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's a part of #1499. The question is, if you can select pods using a label selector, how will the computational resources of all pods work? And why selecting pods by namespace label selector differs from pod label selector in that case ?

Copy link
Author

Choose a reason for hiding this comment

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

Code moved to the preEvictionFilter. Please check it again.

Copy link
Author

Choose a reason for hiding this comment

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

@ingvagabund hello. Can you help me ? Now namespaces list by label selector calculated for every pod which is passed to the PreEvictionFilter. I think we can calculate namespaces name list and pass it to the PreEvictionFilter to reduce cpu usage (i think we can calculate it on every Descheduler Loop). Please advise where this can be done.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could create a new namespace indexer storing namespaces based on a label selector. Which will give you all the namespaces at any given point for free.

Copy link
Author

Choose a reason for hiding this comment

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

Hello, i rebased to current main and add indexer. Can you please check implementation ? If all ok, i'll add tests.

Copy link
Author

Choose a reason for hiding this comment

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

@ingvagabund hi, please check implementation if you have time.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 2, 2024
@RomanenkoDenys RomanenkoDenys force-pushed the add-namespace-label-selector branch from 35f4eba to 056805f Compare September 4, 2024 08:14
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 4, 2024
@RomanenkoDenys RomanenkoDenys force-pushed the add-namespace-label-selector branch 2 times, most recently from a619cfc to 1b6910e Compare September 4, 2024 08:29
@RomanenkoDenys RomanenkoDenys marked this pull request as draft September 4, 2024 12:26
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 4, 2024
@RomanenkoDenys
Copy link
Author

/ok-to-test

would you please squash your commits?

Yes, when i stabilize code, i will squash commits. Thank you !

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 20, 2024
@clementnuss
Copy link

@RomanenkoDenys do you need help ? we will soon need that feature, I'm happy to take this PR to completion and fix the open points.
PS, available on K8s slack to further discuss.

@RomanenkoDenys RomanenkoDenys force-pushed the add-namespace-label-selector branch from 3d0cee3 to bfacd76 Compare October 28, 2024 14:29
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2024
@RomanenkoDenys
Copy link
Author

RomanenkoDenys commented Oct 28, 2024

@RomanenkoDenys do you need help ? we will soon need that feature, I'm happy to take this PR to completion and fix the open points. PS, available on K8s slack to further discuss.

Hello, no, thanks. Today i pushed new implementation as we discussed with @ingvagabundand and rebase to current master branch. I need one more day to do some tests. Can you check PR after that ? If implementation is ok i'll write tests for it.

@RomanenkoDenys
Copy link
Author

@clementnuss can you please check implementation ?

@clementnuss
Copy link

@clementnuss can you please check implementation ?

I could but I'm not a contributor of the repo, sorry if my comment implied that. I think it's best if the assigned people have a chance to look at it, I'd have to first get familiar with the codebase. sorry!

@ingvagabund
Copy link
Contributor

/test all

@k8s-ci-robot
Copy link
Contributor

@RomanenkoDenys: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-descheduler-verify-master 0dd74d4 link true /test pull-descheduler-verify-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.


// check pod by namespace label filter
indexName := "namespaceWithLabelSelector"
indexer, err := getNamespacesListByLabelSelector(indexName, d.args.NamespaceLabelSelector, d.handle)
Copy link
Contributor

@ingvagabund ingvagabund Dec 6, 2024

Choose a reason for hiding this comment

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

The indexer needs to be created before any of the plugins start running. Otherwise, the indexer cache might not get populated properly. In New function. In the same manner as getPodIndexerByOwnerRefs is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants