From b56d30e32a56dfdc478a93f10c7d25d99a73688c Mon Sep 17 00:00:00 2001 From: carlory Date: Thu, 20 Feb 2025 18:06:56 +0800 Subject: [PATCH] fix flaky test: Subpath Container restart should verify that container can restart successfully after configmaps modified Signed-off-by: carlory --- test/e2e/framework/pod/utils.go | 12 ++++++++++++ test/e2e/storage/testsuites/subpath.go | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/pod/utils.go b/test/e2e/framework/pod/utils.go index fa0a63c8467..316517e0fec 100644 --- a/test/e2e/framework/pod/utils.go +++ b/test/e2e/framework/pod/utils.go @@ -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} diff --git a/test/e2e/storage/testsuites/subpath.go b/test/e2e/storage/testsuites/subpath.go index 1fb4c3ca95e..34d35e53768 100644 --- a/test/e2e/storage/testsuites/subpath.go +++ b/test/e2e/storage/testsuites/subpath.go @@ -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)