kubernetes: kubelet does not honor shortened grace period on already-deleting pod

What happened:

Delete a pod with a grace period of 120 seconds, then again with 60 seconds. It will still wait until the first 120 time elapses to delete the pod.

What you expected to happen:

For it to use the new grace period of 60 seconds

How to reproduce it (as minimally and precisely as possible):

ben@shadowfax:~$ kubectl get pod -o yaml | egrep -i 'term|del'
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900

ben@shadowfax:~$ kubectl delete pod $(kubectl get pods | grep python | grep Running | cut -f1 -d' ') --grace-period=60
pod "python-645896764c-f5p9k" deleted

ben@shadowfax:~$ kubectl get pod -o yaml | egrep -i 'term|del'
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900
    deletionGracePeriodSeconds: 60
    deletionTimestamp: "2019-10-02T16:27:50Z"
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900

ben@shadowfax:~$ kubectl delete pod $(kubectl get pods | grep python | grep Running | cut -f1 -d' ') --grace-period=10
pod "python-645896764c-cfsjz" deleted

ben@shadowfax:~$ kubectl get pod -o yaml | egrep -i 'term|del'
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900
    deletionGracePeriodSeconds: 10
    deletionTimestamp: "2019-10-02T16:27:15Z"
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900
    deletionGracePeriodSeconds: 60
    deletionTimestamp: "2019-10-02T16:27:50Z"
      blockOwnerDeletion: true
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
    terminationGracePeriodSeconds: 900

Environment:

  • Kubernetes version (use kubectl version): 1.14
  • Cloud provider or hardware configuration: Rancher/RKE/Hyperkube
  • OS (e.g: cat /etc/os-release): Ubuntu 18.04
  • Install tools: RKE/Rancher

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 18 (13 by maintainers)

Most upvoted comments

We run into this while writing an E2E test (#121491) for Job that does the following:

  1. create a Job
  2. wait for pod to exist and do a regular pod delete
  3. do some asserts in the job status
  4. do a pod delete with 0 grace period
  5. do some asserts in the job status

step 4 doesn’t have any effect because of this issue. Note that Pods that belong to Jobs have finalizers, so it wouldn’t be immediately deleted from the apiserver. This would be useful so that we don’t have to wait for the pod to reach the grace period.

For now, we just shortened the grace period to a value that we hope would prevent flakes: 5s.

/assign

This is something I’m working on with #113606