test/e2e: migrate TestDeschedulingInterval to run descheduler as an image#1861
test/e2e: migrate TestDeschedulingInterval to run descheduler as an image#1861Sanil2108 wants to merge 2 commits into
Conversation
…mage Per kubernetes-sigs#1478, the e2e suite is being moved off in-process descheduler runs and onto deployments of the descheduler image so the tests exercise the real shipped artifact. TestDeschedulingInterval verifies the run-once-and-exit lifecycle when no `--descheduling-interval` is set. The previous version called `descheduler.RunDeschedulerStrategies` directly, which doesn't reflect the production code path. The new version creates a one-shot Pod (restartPolicy=Never, no `--descheduling-interval` flag, no liveness probe — irrelevant for a one-shot run) and asserts the Pod reaches `Succeeded` phase within 3 minutes. A small `newDeschedulerOneShotPod` helper derives the Pod from the existing `deschedulerDeployment` template so the container image, security context, volume mounts, and other plumbing stay in lock-step with the long-running tests. Refs kubernetes-sigs#1478 Signed-off-by: Sanil2108 <sanilkhurana7@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @Sanil2108! |
|
Hi @Sanil2108. 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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
| // meaningful, and a slow first probe could race the clean exit. | ||
| func newDeschedulerOneShotPod(testName, policyConfigMapName string) *v1.Pod { | ||
| deploymentTemplate := deschedulerDeployment(testName) | ||
| podTemplate := deploymentTemplate.Spec.Template |
There was a problem hiding this comment.
Used only once, can be inlined
| deploymentTemplate := deschedulerDeployment(testName) | ||
| podTemplate := deploymentTemplate.Spec.Template | ||
|
|
||
| podSpec := podTemplate.Spec |
There was a problem hiding this comment.
This variable can be inlined as well. Even though this makes the path a bit longer keeping it makes the code easier to read.
| podSpec := podTemplate.Spec | ||
| podSpec.RestartPolicy = v1.RestartPolicyNever | ||
|
|
||
| container := podSpec.Containers[0] |
|
|
||
| // Empty policy is fine — we are testing the run-once-and-exit lifecycle, not | ||
| // any specific descheduling decision. | ||
| deschedulerPolicyConfigMapObj, err := deschedulerPolicyConfigMap(&apiv1alpha2.DeschedulerPolicy{}) |
There was a problem hiding this comment.
deschedulerPolicyConfigMapObj's .Name, resp. .Namespace are not changed. newDeschedulerOneShotPod can be simplified to keep the original CM name.
| // follows the run-once-and-exit code path. | ||
| // - No liveness probe — a one-shot run isn't long enough to make probing | ||
| // meaningful, and a slow first probe could race the clean exit. | ||
| func newDeschedulerOneShotPod(testName, policyConfigMapName string) *v1.Pod { |
There was a problem hiding this comment.
Alternatively, you could define a new deschedulerPodSpec from deschedulerDeployment and have deschedulerDeployment invoke it internally. Then consume it here as well to avoid creating the whole deployment and dropping everything but the pod template.
|
|
||
| container := podSpec.Containers[0] | ||
| container.Args = []string{ | ||
| "--policy-config-file", "/policy-dir/policy.yaml", |
There was a problem hiding this comment.
Instead of resetting the args you could have deschedulerPodSpec take the descheduling interval value (set to 0 in this case). To avoid exposing the actual arguments and keeping only a single place where the binary args are set.
There's already a test under e2e_evictioninbackground_test.go that resets the args. So you are not breaking any convention here. Yet, if there's a way to avoid exposing the arguments/implementation details it's still preferable.
| } | ||
| } | ||
|
|
||
| return &v1.Pod{ |
There was a problem hiding this comment.
Have you considered running it as a Job? To avoid the cases where a pod gets evicted in-flight before it finishes? E.g. due to resource constraints. Creating a job can help with re-creating the pod in these cases. To avoid some of the potential flakes.
|
/ok-to-test |
Remove the policyConfigMapName parameter — deschedulerPolicyConfigMap always returns a CM named "descheduler-policy-configmap", which is exactly what deschedulerDeployment mounts, so the volume-name replacement loop was a no-op. Also inline the intermediate deploymentTemplate and podTemplate variables, each of which was used only once to reach the next field. Signed-off-by: Sanil Khurana <sanilkhurana7@gmail.com> Signed-off-by: SanilK2108 <sanil.khurana@atlan.com>
|
|
Thanks for the thorough review, @ingvagabund! Pushed a follow-up that addresses the feedback:
On the two alternative suggestions:
|
|
/retest-required |
|
Thank you for keeping the PR in a good shape :)
By all means :)
Please proceed. |
|
@Sanil2108: The following test failed, say
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. DetailsInstructions 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. |
Summary
Per #1478, the e2e suite is being moved off in-process descheduler runs and onto deployments of the descheduler image so the tests exercise the real shipped artifact. `TestDeschedulingInterval` was one of the two remaining cases (along with `TestClientConnectionConfiguration`).
What this changes
`TestDeschedulingInterval` verifies the run-once-and-exit lifecycle when no `--descheduling-interval` is set. The previous version called `descheduler.RunDeschedulerStrategies` directly, which doesn't reflect the production code path. The new version:
The helper derives the Pod from the existing `deschedulerDeployment` template so the container image, security context, volume mounts, and SA stay in lock-step with the long-running tests.
Removed
The old in-process `TestDeschedulingInterval` in `test/e2e/e2e_test.go` and the now-unused `options` and `pkg/descheduler` imports it pulled in.
Out of scope
`TestClientConnectionConfiguration` is intentionally not migrated here — the maintainer noted it's "tricky" because the descheduler doesn't currently expose the custom client configuration. Happy to take that as a follow-up if you'd like to scope it.
Test plan
Refs #1478