mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
rkt: Refactor grace termination period.
Add `TimeoutStopSec` service option to support grace termination.
This commit is contained in:
parent
fae7285b00
commit
4329ba700f
@ -1135,6 +1135,7 @@ func (r *Runtime) preparePod(pod *api.Pod, podIP string, pullSecrets []api.Secre
|
||||
newUnitOption("Service", "ExecStopPost", markPodFinished),
|
||||
// This enables graceful stop.
|
||||
newUnitOption("Service", "KillMode", "mixed"),
|
||||
newUnitOption("Service", "TimeoutStopSec", fmt.Sprintf("%ds", getPodTerminationGracePeriodInSecond(pod))),
|
||||
// Track pod info for garbage collection
|
||||
newUnitOption(unitKubernetesSection, unitPodUID, string(pod.UID)),
|
||||
newUnitOption(unitKubernetesSection, unitPodName, pod.Name),
|
||||
@ -1554,14 +1555,22 @@ func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) waitPreStopHooks(pod *api.Pod, runningPod *kubecontainer.Pod) {
|
||||
gracePeriod := int64(minimumGracePeriodInSeconds)
|
||||
func getPodTerminationGracePeriodInSecond(pod *api.Pod) int64 {
|
||||
var gracePeriod int64
|
||||
switch {
|
||||
case pod.DeletionGracePeriodSeconds != nil:
|
||||
gracePeriod = *pod.DeletionGracePeriodSeconds
|
||||
case pod.Spec.TerminationGracePeriodSeconds != nil:
|
||||
gracePeriod = *pod.Spec.TerminationGracePeriodSeconds
|
||||
}
|
||||
if gracePeriod < minimumGracePeriodInSeconds {
|
||||
gracePeriod = minimumGracePeriodInSeconds
|
||||
}
|
||||
return gracePeriod
|
||||
}
|
||||
|
||||
func (r *Runtime) waitPreStopHooks(pod *api.Pod, runningPod *kubecontainer.Pod) {
|
||||
gracePeriod := getPodTerminationGracePeriodInSecond(pod)
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user