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

Filter pods by namespaces #338

Merged

Conversation

ingvagabund
Copy link
Contributor

@ingvagabund ingvagabund commented Jul 11, 2020

Fixes: #251

E2e for the exclude namespaces part are deleting all pods from all namespaces but default which are passing IsEvictable. It can be tricky when the test is run over a cluster with pods that are not supposed to be evicted during the test. Though, I don't see any other way how to do it now. On the other hand, running the descheduler is always destructive so it needs to be run under certain assumptions/conditions.

With introduction of included namespaces one can configure the same strategy with with different conditions for eviction. E.g. evict pods in namespace N1 that are older than 1h but in namespace N2 only pods older than 2h.

The following strategies are subject to namespace filtering now:

  • RemovePodsViolatingInterPodAntiAffinity
  • RemovePodsViolatingNodeAffinity
  • RemovePodsViolatingNodeTaints
  • RemovePodsHavingTooManyRestarts
  • PodLifeTime

Note: the policy config has backward incompatible changes for which we need to bump the version to v1alpha2

TODO:

  • add namespace filters
  • add validation of params
  • e2e for namespace filtering
  • docs

Built on top of #343

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 11, 2020
@ingvagabund ingvagabund changed the title WIP: Filter out pods by namespaces WIP: Filter pods by namespaces Jul 11, 2020
@ingvagabund ingvagabund changed the title WIP: Filter pods by namespaces Filter pods by namespaces Jul 13, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 13, 2020
@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from 1875a45 to c5c8e76 Compare July 13, 2020 14:30
@ingvagabund
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 13, 2020
@ingvagabund
Copy link
Contributor Author

@seanmalloy I diverged a bit from the proposal renaming includeNamespaces to just include. The same for excludeNamespaces as the keyword Namespaces is already mentioned in the tree:

namespaces:
  includeNamespaces:
  - ns1
  - ns2
  excludeNamespaces:
  - ns3
  - ns4

@ingvagabund
Copy link
Contributor Author

@ingvagabund
Copy link
Contributor Author

@seanmalloy @damemi @lixiang233 PTAL

@ingvagabund
Copy link
Contributor Author

We need to have make test-e2e run through Prow before this gets merged: kubernetes/test-infra#18292

@ingvagabund
Copy link
Contributor Author

/test pull-descheduler-test-e2e-k8s-master

@k8s-ci-robot
Copy link
Contributor

@ingvagabund: The specified target(s) for /test were not found.
The following commands are available to trigger jobs:

  • /test pull-descheduler-verify-master
  • /test pull-descheduler-verify-build-master
  • /test pull-descheduler-unit-test-master-master

Use /test all to run all jobs.

In response to this:

/test pull-descheduler-test-e2e-k8s-master

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/test-infra repository.

@damemi
Copy link
Contributor

damemi commented Jul 13, 2020

Maybe a close/reopen will pull in the new test
/close

@k8s-ci-robot
Copy link
Contributor

@damemi: Closed this PR.

In response to this:

Maybe a close/reopen will pull in the new test
/close

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/test-infra repository.

@damemi
Copy link
Contributor

damemi commented Jul 13, 2020

/reopen

@k8s-ci-robot k8s-ci-robot reopened this Jul 13, 2020
@k8s-ci-robot
Copy link
Contributor

@damemi: Reopened this PR.

In response to this:

/reopen

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/test-infra repository.

@damemi
Copy link
Contributor

damemi commented Jul 13, 2020

Opened #340 to try and fix the e2e

@ingvagabund
Copy link
Contributor Author

/retest

)

type Options struct {
filter func(pod *v1.Pod) bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to make filter a list of filter funcs, so that we can easily add more filters to descheduler without changing other funcs in pod util.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can always create function which will call all filter functions:

func(pod *v1.Pod) bool {
	return filter1(pod) && ... filtern(pod)
}

and pass into WithFilter.

pkg/api/types.go Show resolved Hide resolved
@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from c5c8e76 to 238a2ec Compare July 14, 2020 14:27
Copy link
Contributor

@damemi damemi left a comment

Choose a reason for hiding this comment

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

My only real comment is that I think it should be clear that you can only set either Include or Exclude, rather than implicitly preferring one over the other

pkg/api/types.go Show resolved Hide resolved
pkg/api/v1alpha1/types.go Outdated Show resolved Hide resolved
@@ -67,7 +67,7 @@ func TestListPodsOnANode(t *testing.T) {
}
return true, nil, fmt.Errorf("Failed to list: %v", list)
})
pods, _ := ListPodsOnANode(context.TODO(), fakeClient, testCase.node, nil)
pods, _ := ListPodsOnANode(context.TODO(), fakeClient, testCase.node)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 nice, we can get rid of these nils

!nodeutil.PodFitsCurrentNode(pod, node) &&
nodeutil.PodFitsAnyNode(pod, nodes)
}),
podutil.WithNamespaces(strategy.Params.Namespaces.Include),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now how the strategies can easily control whether they implement the include/exclude. Cool!

@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from 238a2ec to 6628814 Compare July 15, 2020 12:17
@k8s-ci-robot k8s-ci-robot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 15, 2020
test/e2e/e2e_test.go Outdated Show resolved Hide resolved
@damemi
Copy link
Contributor

damemi commented Jul 21, 2020

/retest

@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch 6 times, most recently from 57aaf97 to 2306f0c Compare July 22, 2020 13:22
@ingvagabund
Copy link
Contributor Author

/retest


includePodNames := getPodNames(podList.Items)
// validate all pod were deleted
if len(intersectStrings(initialPodNames, includePodNames)) > 0 {
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 consider using sets.String

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as the slices are not too long, the naive implementation is fine.

}
}
t.Logf("All %v pods are terminating", intersectStrings(initialPodNames, includePodNames))
return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think you need this, you have a return at the end of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

t.Logf("Waiting until %v pods get deleted", intersectStrings(initialPodNames, includePodNames))
// check if there's at least one pod not in Terminating state
for _, pod := range podList.Items {
if pod.DeletionTimestamp == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is including the newly created pods, so I think you just want to iterate over initialPods? The errors in CI are failing against a pod that's not in your intersect list: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_descheduler/338/pull-descheduler-test-e2e-k8s-master-1-16/1285935763120197633#1:build-log.txt%3A272

     e2e_test.go:301: Waiting until [test-rc-podlifetime-9wqm7 test-rc-podlifetime-fvqt2 test-rc-podlifetime-hprj9 test-rc-podlifetime-q59m7 test-rc-podlifetime-vrdmk] pods get deleted
    e2e_test.go:305: Pod test-rc-podlifetime-8lh7l not in terminating state 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split it into two tests, each one running the strategy over separate namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah good idea

@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from 6ec235f to 69cf370 Compare July 27, 2020 08:32
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 27, 2020

@ingvagabund: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-descheduler-test-e2e-k8s-master 49636c4 link /test pull-descheduler-test-e2e-k8s-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/test-infra repository. I understand the commands that are listed here.

@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from 69cf370 to 9cb7a95 Compare July 27, 2020 08:45
@ingvagabund ingvagabund force-pushed the filter-out-pods-by-namespaces branch from 2fd939a to 42db316 Compare July 27, 2020 09:00
Copy link
Contributor

@damemi damemi left a comment

Choose a reason for hiding this comment

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

/approve
thanks @ingvagabund this looks good to me
@seanmalloy wdyt?

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: damemi, ingvagabund

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 Jul 27, 2020
@seanmalloy
Copy link
Member

/kind feature

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 28, 2020
@seanmalloy
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 Jul 28, 2020
@k8s-ci-robot k8s-ci-robot merged commit eee41ee into kubernetes-sigs:master Jul 28, 2020
@ingvagabund ingvagabund deleted the filter-out-pods-by-namespaces branch July 28, 2020 16:03
briend pushed a commit to briend/descheduler that referenced this pull request Feb 11, 2022
…ds-by-namespaces

Filter pods by namespaces
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. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Descheduling for a specific namespace
5 participants