mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	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:
		@@ -31,8 +31,20 @@ import (
 | 
				
			|||||||
	"k8s.io/utils/pointer"
 | 
						"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"
 | 
					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.
 | 
					// GenerateScriptCmd generates the corresponding command lines to execute a command.
 | 
				
			||||||
func GenerateScriptCmd(command string) []string {
 | 
					func GenerateScriptCmd(command string) []string {
 | 
				
			||||||
	return []string{"/bin/sh", "-c", command}
 | 
						return []string{"/bin/sh", "-c", command}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -793,10 +793,10 @@ func testPodContainerRestartWithHooks(ctx context.Context, f *framework.Framewor
 | 
				
			|||||||
	pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
 | 
						pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pod.Spec.Containers[0].Image = e2epod.GetDefaultTestImage()
 | 
						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[0].Args = nil
 | 
				
			||||||
	pod.Spec.Containers[1].Image = e2epod.GetDefaultTestImage()
 | 
						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
 | 
						pod.Spec.Containers[1].Args = nil
 | 
				
			||||||
	hooks.AddLivenessProbe(pod, probeFilePath)
 | 
						hooks.AddLivenessProbe(pod, probeFilePath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user