Skip to content

Commit

Permalink
Merge pull request #98103 from gjkim42/delete-static-pod-gracefully
Browse files Browse the repository at this point in the history
Delete static pod gracefully and fix mirrorPodTerminationMap leak
  • Loading branch information
k8s-ci-robot committed Jan 19, 2021
2 parents 13d40ac + 1563fb6 commit 09f4bae
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/kubelet/kubelet.go
Expand Up @@ -1498,6 +1498,13 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
return nil
}

// If the pod is a static pod and its mirror pod is still gracefully terminating,
// we do not want to start the new static pod until the old static pod is gracefully terminated.
podFullName := kubecontainer.GetPodFullName(pod)
if kl.podKiller.IsMirrorPodPendingTerminationByPodName(podFullName) {
return fmt.Errorf("pod %q is pending termination", podFullName)
}

// Latency measurements for the main workflow are relative to the
// first time the pod was seen by the API server.
var firstSeenTime time.Time
Expand Down Expand Up @@ -1633,7 +1640,6 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {

// Create Mirror Pod for Static Pod if it doesn't already exist
if kubetypes.IsStaticPod(pod) {
podFullName := kubecontainer.GetPodFullName(pod)
deleted := false
if mirrorPod != nil {
if mirrorPod.DeletionTimestamp != nil || !kl.podManager.IsMirrorPodOf(mirrorPod, pod) {
Expand Down Expand Up @@ -1764,6 +1770,9 @@ func (kl *Kubelet) deletePod(pod *v1.Pod) error {
}
podPair := kubecontainer.PodPair{APIPod: pod, RunningPod: &runningPod}

if _, ok := kl.podManager.GetMirrorPodByPod(pod); ok {
kl.podKiller.MarkMirrorPodPendingTermination(pod)
}
kl.podKiller.KillPod(&podPair)

// We leave the volume/directory cleanup to the periodic cleanup routine.
Expand Down Expand Up @@ -2102,9 +2111,6 @@ func (kl *Kubelet) HandlePodRemoves(pods []*v1.Pod) {
kl.handleMirrorPod(pod, start)
continue
}
if _, ok := kl.podManager.GetMirrorPodByPod(pod); ok {
kl.podKiller.MarkMirrorPodPendingTermination(pod)
}
// Deletion is allowed to fail because the periodic cleanup routine
// will trigger deletion again.
if err := kl.deletePod(pod); err != nil {
Expand Down

0 comments on commit 09f4bae

Please sign in to comment.