mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +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),
|
newUnitOption("Service", "ExecStopPost", markPodFinished),
|
||||||
// This enables graceful stop.
|
// This enables graceful stop.
|
||||||
newUnitOption("Service", "KillMode", "mixed"),
|
newUnitOption("Service", "KillMode", "mixed"),
|
||||||
|
newUnitOption("Service", "TimeoutStopSec", fmt.Sprintf("%ds", getPodTerminationGracePeriodInSecond(pod))),
|
||||||
// Track pod info for garbage collection
|
// Track pod info for garbage collection
|
||||||
newUnitOption(unitKubernetesSection, unitPodUID, string(pod.UID)),
|
newUnitOption(unitKubernetesSection, unitPodUID, string(pod.UID)),
|
||||||
newUnitOption(unitKubernetesSection, unitPodName, pod.Name),
|
newUnitOption(unitKubernetesSection, unitPodName, pod.Name),
|
||||||
@ -1554,14 +1555,22 @@ func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runtime) waitPreStopHooks(pod *api.Pod, runningPod *kubecontainer.Pod) {
|
func getPodTerminationGracePeriodInSecond(pod *api.Pod) int64 {
|
||||||
gracePeriod := int64(minimumGracePeriodInSeconds)
|
var gracePeriod int64
|
||||||
switch {
|
switch {
|
||||||
case pod.DeletionGracePeriodSeconds != nil:
|
case pod.DeletionGracePeriodSeconds != nil:
|
||||||
gracePeriod = *pod.DeletionGracePeriodSeconds
|
gracePeriod = *pod.DeletionGracePeriodSeconds
|
||||||
case pod.Spec.TerminationGracePeriodSeconds != nil:
|
case pod.Spec.TerminationGracePeriodSeconds != nil:
|
||||||
gracePeriod = *pod.Spec.TerminationGracePeriodSeconds
|
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{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user