Description
this looks like a bug to me, having deletionTimestamps that fluctuate is confusing at minimum, let me try to understand the timeline:
t0 create pod with finalizer
t1 delete pod -> deletionTimestamp is equal to t1+gracePeriod
at t1 + sleepPeriod -> deletionTimestamp is updated and is equal to t1??
yep, that is confirmed with
apiVersion: v1
kind: Pod
metadata:
name: prestop-example
finalizers:
- test/finalizer
spec:
terminationGracePeriodSeconds: 30
containers:
- name: app-container
image: registry.k8s.io/e2e-test-images/agnhost:2.48
lifecycle:
preStop:
sleep:
seconds: 5
after preStop timestamp goes back in time
$ date && kubectl get pods prestop-example -o yaml | grep -i timestam
Tue Jun 10 11:37:31 AM UTC 2025
creationTimestamp: "2025-06-10T11:36:20Z"
deletionTimestamp: "2025-06-10T11:37:56Z"
$ date && kubectl get pods prestop-example -o yaml | grep -i timestam
Tue Jun 10 11:37:32 AM UTC 2025
creationTimestamp: "2025-06-10T11:36:20Z"
deletionTimestamp: "2025-06-10T11:37:32Z"
it seems the kubelet sends a new DELETE after the prestop hook is executed
I0610 11:55:01.644079 1 httplog.go:134] "HTTP" verb="DELETE" URI="/api/v1/namespaces/default/pods/prestop-example" latency="5.239176ms" userAgent="kubectl/v1.33.1 (linux/amd64) kubernetes/8adc0f0" audit-ID="1b48906d-bda7-4599-8cad-7ff983291186" srcIP="192.168.8.1:54692" apf_pl="global-default" apf_fs="global-default" apf_iseats=1 apf_fseats=0 apf_additionalLatency="0s" apf_execution_time="4.622037ms" resp=200
I0610 11:55:06.982183 1 handler.go:152] kube-aggregator: DELETE "/api/v1/namespaces/default/pods/prestop-example" satisfied by nonGoRestful
I0610 11:55:06.982209 1 handler.go:142] kube-apiserver: DELETE "/api/v1/namespaces/default/pods/prestop-example" satisfied by gorestful with webservice /api/v1
Originally posted by @aojea in #128642 (comment)
The logic that sets the deletion timestamp considering the grace period comes from
kubernetes/pkg/registry/core/pod/strategy.go
Lines 136 to 138 in 54fd2aa
and is added in
kubernetes/staging/src/k8s.io/apiserver/pkg/registry/rest/delete.go
Lines 154 to 169 in da50238
I didn;t have time to trace the preStop hook logic, but it seems on the experiments that it sends a new Delete request , the logic seems to start here