Commit 276fb173 authored by Yifan Gu's avatar Yifan Gu

Refactor pkg/kubelet/kubelet.go: probeContainer().

Put the retry loop in probe.go into a function.
parent 131e8a0e
...@@ -86,16 +86,7 @@ func (kl *Kubelet) probeContainerLiveness(pod *api.BoundPod, status api.PodStatu ...@@ -86,16 +86,7 @@ func (kl *Kubelet) probeContainerLiveness(pod *api.BoundPod, status api.PodStatu
if time.Now().Unix()-dockerContainer.Created < p.InitialDelaySeconds { if time.Now().Unix()-dockerContainer.Created < p.InitialDelaySeconds {
return probe.Success, nil return probe.Success, nil
} }
return kl.runProbeWithRetries(p, pod, status, container, maxProbeRetries)
var result probe.Result
var err error
for i := 0; i < maxProbeRetries; i++ {
result, err = kl.runProbe(p, pod, status, container)
if result == probe.Success {
return probe.Success, err
}
}
return result, err
} }
// probeContainerLiveness probes the readiness of a container. // probeContainerLiveness probes the readiness of a container.
...@@ -108,13 +99,18 @@ func (kl *Kubelet) probeContainerReadiness(pod *api.BoundPod, status api.PodStat ...@@ -108,13 +99,18 @@ func (kl *Kubelet) probeContainerReadiness(pod *api.BoundPod, status api.PodStat
if time.Now().Unix()-dockerContainer.Created < p.InitialDelaySeconds { if time.Now().Unix()-dockerContainer.Created < p.InitialDelaySeconds {
return probe.Failure, nil return probe.Failure, nil
} }
return kl.runProbeWithRetries(p, pod, status, container, maxProbeRetries)
}
var result probe.Result // runProbeWithRetries tries to probe the container in a finite loop, it returns the last result
// if it never succeeds.
func (kl *Kubelet) runProbeWithRetries(p *api.Probe, pod *api.BoundPod, status api.PodStatus, container api.Container, retires int) (probe.Result, error) {
var err error var err error
for i := 0; i < maxProbeRetries; i++ { var result probe.Result
for i := 0; i < retires; i++ {
result, err = kl.runProbe(p, pod, status, container) result, err = kl.runProbe(p, pod, status, container)
if result == probe.Success { if result == probe.Success {
return probe.Success, err return probe.Success, nil
} }
} }
return result, err return result, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment