Stop StartupProbe explicity when successThrethold is reached

This commit is contained in:
mochizuki875 2023-10-13 02:53:08 +00:00
parent 1e827f4b2a
commit aa9a9e86e1
3 changed files with 60 additions and 2 deletions

View File

@ -46,6 +46,10 @@ func getTestRunningStatus() v1.PodStatus {
return getTestRunningStatusWithStarted(true)
}
func getTestNotRunningStatus() v1.PodStatus {
return getTestRunningStatusWithStarted(false)
}
func getTestRunningStatusWithStarted(started bool) v1.PodStatus {
containerStatus := v1.ContainerStatus{
Name: testContainerName,

View File

@ -316,11 +316,14 @@ func (w *worker) doProbe(ctx context.Context) (keepGoing bool) {
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.
// Stop probing until we see a new container ID. This is to reduce the
// chance of hitting #21751, where running `docker exec` when a
// 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.resultRun = 0
}

View File

@ -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) {
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) {
if !c {
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"
expectContinue(t, w, w.doProbe(ctx), msg)
expectResult(t, w, results.Success, msg)
if w.onHold {
if probeType == liveness && w.onHold {
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)
}
}
}