fix flaky test: Subpath Container restart should verify that container can restart successfully after configmaps modified

Signed-off-by: carlory <baofa.fan@daocloud.io>
This commit is contained in:
carlory 2025-02-20 18:06:56 +08:00
parent c2529e8443
commit b56d30e32a
2 changed files with 14 additions and 2 deletions

View File

@ -31,8 +31,20 @@ import (
"k8s.io/utils/pointer"
)
// This command runs an infinite loop, sleeping for 1 second in each iteration.
// It sets up a trap to exit gracefully when a TERM signal is received.
//
// This is useful for testing scenarios where the container is terminated
// with a zero exit code.
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
// This command will cause the shell to remain in a sleep state indefinitely,
// and it won't exit unless it receives a KILL signal.
//
// This is useful for testing scenarios where the container is terminated
// with a non-zero exit code.
const InfiniteSleepCommandWithoutGracefulShutdown = "sleep infinity"
// GenerateScriptCmd generates the corresponding command lines to execute a command.
func GenerateScriptCmd(command string) []string {
return []string{"/bin/sh", "-c", command}

View File

@ -793,10 +793,10 @@ func testPodContainerRestartWithHooks(ctx context.Context, f *framework.Framewor
pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
pod.Spec.Containers[0].Image = e2epod.GetDefaultTestImage()
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommandWithoutGracefulShutdown)
pod.Spec.Containers[0].Args = nil
pod.Spec.Containers[1].Image = e2epod.GetDefaultTestImage()
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommandWithoutGracefulShutdown)
pod.Spec.Containers[1].Args = nil
hooks.AddLivenessProbe(pod, probeFilePath)