Merge pull request #130306 from carlory/fix-130268

fix flaky test: Subpath Container restart should verify that container can restart successfully after configmaps modified
This commit is contained in:
Kubernetes Prow Robot 2025-02-23 23:00:28 -08:00 committed by GitHub
commit aa96283764
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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)