mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 07:13:53 +00:00
Stop StartupProbe explicity when successThrethold is reached
This commit is contained in:
parent
1e827f4b2a
commit
aa9a9e86e1
@ -46,6 +46,10 @@ func getTestRunningStatus() v1.PodStatus {
|
|||||||
return getTestRunningStatusWithStarted(true)
|
return getTestRunningStatusWithStarted(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTestNotRunningStatus() v1.PodStatus {
|
||||||
|
return getTestRunningStatusWithStarted(false)
|
||||||
|
}
|
||||||
|
|
||||||
func getTestRunningStatusWithStarted(started bool) v1.PodStatus {
|
func getTestRunningStatusWithStarted(started bool) v1.PodStatus {
|
||||||
containerStatus := v1.ContainerStatus{
|
containerStatus := v1.ContainerStatus{
|
||||||
Name: testContainerName,
|
Name: testContainerName,
|
||||||
|
@ -316,11 +316,14 @@ func (w *worker) doProbe(ctx context.Context) (keepGoing bool) {
|
|||||||
|
|
||||||
w.resultsManager.Set(w.containerID, result, w.pod)
|
w.resultsManager.Set(w.containerID, result, w.pod)
|
||||||
|
|
||||||
if (w.probeType == liveness || w.probeType == startup) && result == results.Failure {
|
if (w.probeType == liveness && result == results.Failure) || w.probeType == startup {
|
||||||
// The container fails a liveness/startup check, it will need to be restarted.
|
// The container fails a liveness/startup check, it will need to be restarted.
|
||||||
// Stop probing until we see a new container ID. This is to reduce the
|
// Stop probing until we see a new container ID. This is to reduce the
|
||||||
// chance of hitting #21751, where running `docker exec` when a
|
// chance of hitting #21751, where running `docker exec` when a
|
||||||
// container is being stopped may lead to corrupted container state.
|
// container is being stopped may lead to corrupted container state.
|
||||||
|
// In addition, if the container succeeds a startup probe, we should stop probing
|
||||||
|
// until the container is restarted.
|
||||||
|
// This is to prevent extra Probe executions #117153.
|
||||||
w.onHold = true
|
w.onHold = true
|
||||||
w.resultRun = 0
|
w.resultRun = 0
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,48 @@ func TestSuccessThreshold(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStartupProbeSuccessThreshold(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
m := newTestManager()
|
||||||
|
successThreshold := 1
|
||||||
|
failureThreshold := 3
|
||||||
|
w := newTestWorker(m, startup, v1.Probe{SuccessThreshold: int32(successThreshold), FailureThreshold: int32(failureThreshold)})
|
||||||
|
m.statusManager.SetPodStatus(w.pod, getTestNotRunningStatus())
|
||||||
|
|
||||||
|
m.prober.exec = fakeExecProber{probe.Success, nil}
|
||||||
|
|
||||||
|
for i := 0; i < successThreshold+1; i++ {
|
||||||
|
msg := fmt.Sprintf("%d success", successThreshold)
|
||||||
|
expectContinue(t, w, w.doProbe(ctx), msg)
|
||||||
|
expectResult(t, w, results.Success, msg)
|
||||||
|
expectResultRun(t, w, 0, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartupProbeFailureThreshold(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
m := newTestManager()
|
||||||
|
successThreshold := 1
|
||||||
|
failureThreshold := 3
|
||||||
|
w := newTestWorker(m, startup, v1.Probe{SuccessThreshold: int32(successThreshold), FailureThreshold: int32(failureThreshold)})
|
||||||
|
m.statusManager.SetPodStatus(w.pod, getTestNotRunningStatus())
|
||||||
|
|
||||||
|
m.prober.exec = fakeExecProber{probe.Failure, nil}
|
||||||
|
|
||||||
|
for i := 0; i < failureThreshold+1; i++ {
|
||||||
|
msg := fmt.Sprintf("%d failure", i+1)
|
||||||
|
expectContinue(t, w, w.doProbe(ctx), msg)
|
||||||
|
if i < failureThreshold-1 {
|
||||||
|
expectResult(t, w, results.Unknown, msg)
|
||||||
|
expectResultRun(t, w, i+1, msg)
|
||||||
|
} else {
|
||||||
|
msg := fmt.Sprintf("%d failure", failureThreshold)
|
||||||
|
expectResult(t, w, results.Failure, msg)
|
||||||
|
expectResultRun(t, w, 0, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCleanUp(t *testing.T) {
|
func TestCleanUp(t *testing.T) {
|
||||||
m := newTestManager()
|
m := newTestManager()
|
||||||
|
|
||||||
@ -315,6 +357,13 @@ func expectResult(t *testing.T, w *worker, expectedResult results.Result, msg st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func expectResultRun(t *testing.T, w *worker, expectedResultRun int, msg string) {
|
||||||
|
if w.resultRun != expectedResultRun {
|
||||||
|
t.Errorf("[%s - %s] Expected result to be %v, but was %v",
|
||||||
|
w.probeType, msg, expectedResultRun, w.resultRun)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func expectContinue(t *testing.T, w *worker, c bool, msg string) {
|
func expectContinue(t *testing.T, w *worker, c bool, msg string) {
|
||||||
if !c {
|
if !c {
|
||||||
t.Errorf("[%s - %s] Expected to continue, but did not", w.probeType, msg)
|
t.Errorf("[%s - %s] Expected to continue, but did not", w.probeType, msg)
|
||||||
@ -366,8 +415,10 @@ func TestOnHoldOnLivenessOrStartupCheckFailure(t *testing.T) {
|
|||||||
msg = "hold lifted"
|
msg = "hold lifted"
|
||||||
expectContinue(t, w, w.doProbe(ctx), msg)
|
expectContinue(t, w, w.doProbe(ctx), msg)
|
||||||
expectResult(t, w, results.Success, msg)
|
expectResult(t, w, results.Success, msg)
|
||||||
if w.onHold {
|
if probeType == liveness && w.onHold {
|
||||||
t.Errorf("Prober should not be on hold anymore")
|
t.Errorf("Prober should not be on hold anymore")
|
||||||
|
} else if probeType == startup && !w.onHold {
|
||||||
|
t.Errorf("Prober should be on hold due to %s check success", probeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user