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

Test pod becoming schedulable when another pod is added or updated #92074

Conversation

nodo
Copy link
Contributor

@nodo nodo commented Jun 12, 2020

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
It adds two integration tests.

The first one is for a pod creation event. The pod we are testing is scheduled because a new pod with affinity his scheduled.

The second one is for a pod update event. The pod we are testing is scheduled because a previously scheduled pod is updated with a new label (which correspond to the affinity of the pod we are testing).

Which issue(s) this PR fixes:
Fixes of #91111

Does this PR introduce a user-facing change?:

NONE

@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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 12, 2020
@k8s-ci-robot
Copy link
Contributor

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

@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 Jun 12, 2020
@k8s-ci-robot k8s-ci-robot added area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 12, 2020
@nodo
Copy link
Contributor Author

nodo commented Jun 12, 2020

/cc @alculquicondor

Copy link
Member

@Huang-Wei Huang-Wei left a comment

Choose a reason for hiding this comment

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

I'd prefer to add other tests for pod-antiaffinity like this:

  • init: create 2 nodes and 2 pods with label "foo", with pod-antiaffinity to not co-exist with pod with label "foo" - so they don't get scheduled to the same node
  • pod: create a regular pod with label "foo"
  • update: delete one of the 2 pods we created in init()

And we can come up with another test:

  • init: create 2 nodes and 2 pods with label "foo", with nodeAffinity (or nodeSelector) to land on node1/node2 accordingly
  • pod: create a pod with label "foo", and with pod-antiaffinity to not co-exist with pod with label "foo"
  • update: delete one of the 2 pods we created in init()

@@ -1106,7 +1106,49 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
return nil
},
},
// TODO(#91111): Add more test cases.
{
name: "other pod gets added",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "other pod gets added",
name: "pod with pod-affinity gets added",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please, correct me if I am wrong, but I thought the purpose of #91111 is to add coverage to the events that triggers the scheduler. The tests you suggest seems to trigger the scheduler when a "pod gets deleted" which is covered already in #91734.

What makes you prefer these tests?

cc @alculquicondor

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's back up a bit.

The idea of these tests is to cover the different events that change the state of the cluster. Ideally, we cover all variations of events that we could think of. But since these are integrations tests, and they are expensive, we should be a bit more conservative.

Then, we can cover the cases where we now a different path is taken. That is not the case for delete: all pods are moved back to the active queue. So I'm happy to just keep the test we have that uses the Fit plugin. The rest of the affinity workflow is already covered with unit tests.

wdyt @Huang-Wei

Copy link
Member

Choose a reason for hiding this comment

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

@nodo @alculquicondor In terms of using integration tests to only cover different paths, I'm fine with holding off the extra deletion tests.

However, I think we missed the Update path, any thoughts on adding a test like this:

  • init: create a node and a pod (without any label). The pod is expected to be scheduled.
  • pod: create a pod without any lane, and with pod-affinity to co-exist with label "foo". The pod is expected to be pending - just like the current test.
  • update: apply label "foo" to the scheduled pod. Then it's expected to trigger cache#UpdatePod(), and the pending pod is expected to be scheduled.

Copy link
Member

Choose a reason for hiding this comment

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

Is that a valid case? Can you change labels in running Pods?
If so, I'm ok with having that test. Otherwise it's unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

I tried both plain pod and podTemplate, they're both mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, it makes sense to me. I will add an additional test in this PR.

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 forget to update the name of the test to be more descriptive :)

pod with pod-affinity gets added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aha! good point, thanks! :)

Comment on lines +1116 to +1121
if err := utils.AddLabelsToNode(cs, node.Name, map[string]string{"region": "test"}); err != nil {
return fmt.Errorf("cannot add labels to node: %v", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Cannot we just initialize the node with the labels?

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 was replicating the same logic in this other test: https://github.com/kubernetes/kubernetes/blob/master/test/integration/scheduler/predicates_test.go#L47-L58.

I could not find a test utility to create nodes with labels, do you know if there is any? If not I am not sure it's worth to add, but what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Sigh... we should really be cleaning existing mistakes, otherwise, other developers will copy them over and over.

For now, please leave a TODO here, as well as https://github.com/kubernetes/kubernetes/blob/master/test/integration/scheduler/predicates_test.go#L47-L58. A good and consistent way to craft nodes/pods is to use pkg/scheduler/testing/wrapper.go - but it's a big item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, I am happy to work on the cleanup after this PR.

@alculquicondor
Copy link
Member

Let's just get all test cases described by @Huang-Wei in this PR

@Huang-Wei
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 Jun 15, 2020
@nodo nodo changed the title Add test case for a pod becoming schedulable when another pod is added Test pod becoming schedulable when another pod is added or updated Jun 16, 2020
@Huang-Wei
Copy link
Member

/retest

test/integration/scheduler/predicates_test.go Outdated Show resolved Hide resolved
@@ -1106,7 +1106,49 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
return nil
},
},
// TODO(#91111): Add more test cases.
{
name: "other pod gets added",
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 forget to update the name of the test to be more descriptive :)

pod with pod-affinity gets added

test/integration/scheduler/predicates_test.go Outdated Show resolved Hide resolved
@nodo nodo force-pushed the pod-added-unschedulable-pod-integration-tests branch 2 times, most recently from 139a553 to 1e6027f Compare June 16, 2020 18:38
@nodo nodo force-pushed the pod-added-unschedulable-pod-integration-tests branch from 1e6027f to 0c23caf Compare June 16, 2020 18:40
@alculquicondor
Copy link
Member

/approve

will leave lgtm to @Huang-Wei

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, nodo

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 Jun 16, 2020
@Huang-Wei
Copy link
Member

/lgtm

Thanks @nodo.

@Huang-Wei
Copy link
Member

/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 16, 2020
@Huang-Wei
Copy link
Member

/retest

@k8s-ci-robot k8s-ci-robot merged commit e760ecd into kubernetes:master Jun 17, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jun 17, 2020
@nodo nodo deleted the pod-added-unschedulable-pod-integration-tests branch June 17, 2020 05:49
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. area/test 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

None yet

4 participants