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

fix removing pods from podTopologyHints mapping #101615

Merged
merged 1 commit into from May 10, 2021

Conversation

aheng-ch
Copy link
Contributor

@aheng-ch aheng-ch commented Apr 29, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

podTopologyHints records TopologyHints and is indexed by PodUID to ContainerName

s.podTopologyHints[podUID][containerName] = th

but when remove a container, it deletes the record according to the containerID which will result in the record never being deleted
delete(s.podTopologyHints[podUIDString], containerID)

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 29, 2021
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 29, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @aheng-ch!

It looks like this is your first PR to kubernetes/kubernetes 🎉. 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/kubernetes 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
Copy link
Contributor

Hi @aheng-ch. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 29, 2021
@ehashman ehashman added this to Triage in SIG Node PR Triage Apr 29, 2021
@ehashman ehashman moved this from Triage to Waiting on Author in SIG Node PR Triage Apr 29, 2021
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. release-note-none Denotes a PR that doesn't merit a release note. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 30, 2021
@aheng-ch
Copy link
Contributor Author

aheng-ch commented May 4, 2021

/assign @derekwaynecarr @Random-Liu @nolancon

@aheng-ch
Copy link
Contributor Author

aheng-ch commented May 5, 2021

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label May 5, 2021
@aheng-ch
Copy link
Contributor Author

aheng-ch commented May 7, 2021

/cc @jfbai @derekwaynecarr @nolancon

/cc @klueska

@k8s-ci-robot k8s-ci-robot requested a review from klueska May 7, 2021 13:10
@klueska
Copy link
Contributor

klueska commented May 7, 2021

Hi @aheng-ch thanks for finding this issue and submitting your PR. This seems like a legit issue that should actually be backported to 1.20 and 1.21 as well. I will review it more formally early next week.

Copy link
Contributor

@klueska klueska left a comment

Choose a reason for hiding this comment

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

Looks good in general. A few comments.

@@ -94,11 +95,11 @@ func (s *scope) AddHintProvider(h HintProvider) {

// It would be better to implement this function in topologymanager instead of scope
// but topologymanager do not track mapping anymore
func (s *scope) AddContainer(pod *v1.Pod, containerID string) error {
func (s *scope) AddContainer(pod *v1.Pod, container *v1.Container, containerID string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this always returns nil, let's remove the error return value and make this function consistent with the other AddContainer() calls from other components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I will update it

Comment on lines 112 to 126
podUIDString := s.podMap[containerID]
delete(s.podMap, containerID)
if _, exists := s.podTopologyHints[podUIDString]; exists {
delete(s.podTopologyHints[podUIDString], containerID)
podUIDString, containerName, _ := s.podMap.GetContainerRef(containerID)
s.podMap.RemoveByContainerID(containerID)
if _, err := s.podMap.GetContainerID(podUIDString, containerName); err != nil {
delete(s.podTopologyHints[podUIDString], containerName)
if len(s.podTopologyHints[podUIDString]) == 0 {
delete(s.podTopologyHints, podUIDString)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of this feels redundant. I think the following would be sufficient:

if podUIDString, containerName, exists := s.podMap.GetContainerRef(containerID); exists {
	s.podMap.RemoveByContainerID(containerID)
	delete(s.podTopologyHints[podUIDString], containerName)
	if len(s.podTopologyHints[podUIDString]) == 0 {
		delete(s.podTopologyHints, podUIDString)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems ok to delete(s.podTopologyHints[podUIDString], containerName) immediately after s.podMap.RemoveByContainerID(containerID) because we don't use it after the pod is created. But podMap is the mapping of (PodUid, ContainerName) to ContainerID, when a container restart (ContainerID changed), a new record will be added to podMap. Then the contents in podMap would be like ContainerIDOld: {PodUID1, ContainerName1}, ContainerIDNew:{PodUID1, ContainerName1}. If we delete ContainerName1 in podTopologyHints when remove ContainerIDOld from podMap, it will cause the info between podMap and podTopologyHints is inconsistent. So I think it may be better to remove the container from podTopologyHints after deleting all records about this container in podMap.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. You are handling the case where a container with the same podUUID and containerName is started with a different ContainerID (i.e. after a restart). We clearly don't want to delete that new containers topology hints inadvertently.

I think this deserves a comment, since it is not obvious why we would need to re-call into the podMap in this way. How about:

// Get the podUID and containerName associated with the containerID to be removed and remove it
podUIDString, containerName, err := s.podMap.GetContainerRef(containerID)
if err != nil {
	return nil
}
s.podMap.RemoveByContainerID(containerID)

// In cases where a container has been restarted, it's possible that the same podUID and
// containerName are already associated with a *different* containerID now. Only remove
// the TopologyHints associated with that podUID and containerName if this is not true.
if _, err := s.podMap.GetContainerID(podUIDString, containerName); err != nil {
	delete(s.podTopologyHints[podUIDString], containerName)
	if len(s.podTopologyHints[podUIDString]) == 0 {
		delete(s.podTopologyHints, podUIDString)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for your suggestion

Comment on lines 122 to 124
if len1-len2 != 1 || lenHints1-lenHints2 != 1 {
t.Errorf("Remove Pod resulted in error")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we break this into two checks with different errors based on which one was incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you are right, I will update it

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 10, 2021
@klueska
Copy link
Contributor

klueska commented May 10, 2021

Looks good. Let's backport this to 1.20 and 1.21 once this is merged.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aheng-ch, klueska

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 May 10, 2021
@aheng-ch
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind
/test pull-kubernetes-integration

@k8s-ci-robot k8s-ci-robot merged commit 9f9d774 into kubernetes:master May 10, 2021
SIG Node PR Triage automation moved this from Waiting on Author to Done May 10, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone May 10, 2021
@ffromani
Copy link
Contributor

/triage accepted
/priority priority/important-soon
(while important, this doesn't seem to require critical-urgent)

@k8s-ci-robot
Copy link
Contributor

@fromanirh: The label(s) priority/priority/important-soon cannot be applied, because the repository doesn't have them.

In response to this:

/triage accepted
/priority priority/important-soon
(while important, this doesn't seem to require critical-urgent)

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 triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 10, 2021
@ffromani
Copy link
Contributor

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 10, 2021
@aheng-ch aheng-ch deleted the podTopologyHints branch May 14, 2021 09:01
k8s-ci-robot added a commit that referenced this pull request Jun 8, 2021
…1615-origin-release-1.21

Automated cherry pick of #101615: fix removing pods from podTopologyHints mapping
k8s-ci-robot added a commit that referenced this pull request Jun 8, 2021
…1615-origin-release-1.20

Automated cherry pick of #101615: fix removing pods from podTopologyHints mapping
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/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants