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

Delete static pod gracefully and fix mirrorPodTerminationMap leak #98103

Merged
merged 2 commits into from Jan 19, 2021

Conversation

gjkim42
Copy link
Member

@gjkim42 gjkim42 commented Jan 15, 2021

What type of PR is this?
/kind bug

What this PR does / why we need it:

  • Delete static pod gracefully by adding a new static pod after checking if its mirror pod is pending termination.
  • Fix mirrorPodTerminationMap leak

Which issue(s) this PR fixes:

Fixes #97722

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Static pods will be deleted gracefully.

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


/cc @ehashman @rphillips @harche

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jan 15, 2021
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 15, 2021
@k8s-ci-robot
Copy link
Contributor

@gjkim42: GitHub didn't allow me to request PR reviews from the following users: harche.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

What type of PR is this?
/kind bug

What this PR does / why we need it:

  • Delete static pod gracefully by adding a new static pod after checking if its mirror pod is pending termination.
  • Fix mirrorPodTerminationMap leak

Which issue(s) this PR fixes:

Fixes #97722

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Static pods will be deleted gracefully.

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


/cc @ehashman @rphillips @harche

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Jan 15, 2021
@k8s-ci-robot
Copy link
Contributor

@gjkim42: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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. labels Jan 15, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @gjkim42. 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 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 Jan 15, 2021
Comment on lines +1772 to 1777
if _, ok := kl.podManager.GetMirrorPodByPod(pod); ok {
kl.podKiller.MarkMirrorPodPendingTermination(pod)
}
kl.podKiller.KillPod(&podPair)
Copy link
Member Author

@gjkim42 gjkim42 Jan 15, 2021

Choose a reason for hiding this comment

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

For reviewers: ensure podKiller.KillPod to be called

@ehashman ehashman added this to Triage in SIG Node PR Triage Jan 15, 2021
@rphillips
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 Jan 15, 2021
@ehashman ehashman moved this from Triage to Needs Reviewer in SIG Node PR Triage Jan 15, 2021
@rphillips
Copy link
Member

Nice! We will give this a test today or Monday.

Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

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

I think this LGTM...

/assign @harche

@@ -2103,9 +2110,6 @@ func (kl *Kubelet) HandlePodRemoves(pods []*v1.Pod) {
kl.handleMirrorPod(pod, start)
continue
}
if _, ok := kl.podManager.GetMirrorPodByPod(pod); ok {
kl.podKiller.MarkMirrorPodPendingTermination(pod)
}
Copy link
Member

Choose a reason for hiding this comment

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

Ahh, I think I see what's happening here. This code never even gets executed because we'll hit the continue above before ever executing this.

My next question was "should this then go in handleMirrorPod instead?" but that code looks like it's in need of a refactor since 2015... #17251

Copy link
Member Author

@gjkim42 gjkim42 Jan 15, 2021

Choose a reason for hiding this comment

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

The problem I am pointing out is that this code was executed but the kl.deletePod below may return an error before executing podKiller.KillPod. And then we don't have a chance to delete the pending state from the podKiller.mirrorPodTerminationMap(a leak problem). What I fixed is to make sure it calls the podKiller.KillPod.

func (kl *Kubelet) deletePod(pod *v1.Pod) error {
if pod == nil {
return fmt.Errorf("deletePod does not allow nil pod")
}
if !kl.sourcesReady.AllReady() {
// If the sources aren't ready, skip deletion, as we may accidentally delete pods
// for sources that haven't reported yet.
return fmt.Errorf("skipping delete because sources aren't ready yet")
}
kl.podWorkers.ForgetWorker(pod.UID)
// make sure our runtimeCache is at least as fresh as the last container started event we observed.
// this ensures we correctly send graceful deletion signals to all containers we've reported started.
if lastContainerStarted, ok := kl.lastContainerStartedTime.Get(pod.UID); ok {
if err := kl.runtimeCache.ForceUpdateIfOlder(lastContainerStarted); err != nil {
return fmt.Errorf("error updating containers: %v", err)
}
}
// Runtime cache may not have been updated to with the pod, but it's okay
// because the periodic cleanup routine will attempt to delete again later.
runningPods, err := kl.runtimeCache.GetPods()
if err != nil {
return fmt.Errorf("error listing containers: %v", err)
}
runningPod := kubecontainer.Pods(runningPods).FindPod("", pod.UID)
if runningPod.IsEmpty() {
return fmt.Errorf("pod not found")
}
podPair := kubecontainer.PodPair{APIPod: pod, RunningPod: &runningPod}
kl.podKiller.KillPod(&podPair)
// We leave the volume/directory cleanup to the periodic cleanup routine.
return nil
}

@k8s-ci-robot
Copy link
Contributor

@ehashman: GitHub didn't allow me to assign the following users: harche.

Note that only kubernetes members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

I think this LGTM...

/assign @harche

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.

@harche
Copy link
Contributor

harche commented Jan 18, 2021

I verified this PR using the pods mentioned in #97722 and it seems to be fixing the issue. I do not see listen tcp4 :4444: bind: address already in use when I update the static pod indicating the static pod was restarted by respecting terminationGracePeriodSeconds

@rphillips
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 Jan 18, 2021
@gjkim42 gjkim42 force-pushed the delete-static-pod-gracefully branch from 751cf2a to 1563fb6 Compare January 18, 2021 23:57
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 18, 2021
@gjkim42
Copy link
Member Author

gjkim42 commented Jan 19, 2021

/retest

@rphillips
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 Jan 19, 2021
@sjenning
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gjkim42, sjenning

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 Jan 19, 2021
@ehashman
Copy link
Member

/test pull-kubernetes-e2e-gce-100-performance

debian iptables flake

@rphillips
Copy link
Member

/cherry-pick release-1.19

@rphillips
Copy link
Member

/cherry-pick release-1.20

@rphillips
Copy link
Member

doh! I forgot the bot is not setup for cherry picks.

@ehashman
Copy link
Member

@rphillips should this also be pulled into 1.18? is it affected?

@hasheddan
Copy link
Contributor

@rphillips echoing @ehashman's question here. I believe it is applicable to 1.18, but please correct me if I am incorrect.

@ehashman
Copy link
Member

I will TAL

k8s-ci-robot added a commit that referenced this pull request Feb 12, 2021
…103-upstream-release-1.19

Automated cherry pick of #98103: kubelet: Delete static pods gracefully
k8s-ci-robot added a commit that referenced this pull request Feb 13, 2021
…42-upstream-release-1.18

Automated cherry pick of #92442 and #98103
k8s-ci-robot added a commit that referenced this pull request Feb 13, 2021
…103-upstream-release-1.20

Automated cherry pick of #98103: kubelet: Delete static pods gracefully
@gjkim42 gjkim42 deleted the delete-static-pod-gracefully branch February 20, 2021 18:27
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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/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 Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

Static pod should be updated by respecting terminationGracePeriodSeconds
7 participants