From cc1251123bab4a74169c9393b137bcbd184d3fd5 Mon Sep 17 00:00:00 2001 From: HirazawaUi <695097494plus@gmail.com> Date: Sun, 16 Apr 2023 21:21:49 +0800 Subject: [PATCH] use wait to avoid blocking the SIGTERM handler --- test/e2e_node/deleted_pods_test.go | 9 +++++++-- test/e2e_node/node_shutdown_linux_test.go | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/test/e2e_node/deleted_pods_test.go b/test/e2e_node/deleted_pods_test.go index 4541a5b3264..d90629efb9e 100644 --- a/test/e2e_node/deleted_pods_test.go +++ b/test/e2e_node/deleted_pods_test.go @@ -155,12 +155,17 @@ var _ = SIGDescribe("Deleted pods handling [NodeConformance]", func() { Image: imageutils.GetE2EImage(imageutils.BusyBox), Command: []string{"sh", "-c"}, Args: []string{` + sleep 9999999 & + PID=$! _term() { + kill $PID echo "Caught SIGTERM signal!" - exit 0 } + trap _term SIGTERM - while true; do sleep 5; done + wait $PID + + exit 0 `, }, }, diff --git a/test/e2e_node/node_shutdown_linux_test.go b/test/e2e_node/node_shutdown_linux_test.go index 022248a0aca..643d41a5f66 100644 --- a/test/e2e_node/node_shutdown_linux_test.go +++ b/test/e2e_node/node_shutdown_linux_test.go @@ -560,6 +560,11 @@ func getPriorityClass(name string, value int32) *schedulingv1.PriorityClass { } return priority } + +// getGracePeriodOverrideTestPod returns a new Pod object containing a container +// runs a shell script, hangs the process until a SIGTERM signal is received. +// The script waits for $PID to ensure that the process does not exist. +// If priorityClassName is scheduling.SystemNodeCritical, the Pod is marked as critical and a comment is added. func getGracePeriodOverrideTestPod(name string, node string, gracePeriod int64, priorityClassName string) *v1.Pod { pod := &v1.Pod{ TypeMeta: metav1.TypeMeta{ @@ -576,13 +581,16 @@ func getGracePeriodOverrideTestPod(name string, node string, gracePeriod int64, Image: busyboxImage, Command: []string{"sh", "-c"}, Args: []string{` -_term() { - echo "Caught SIGTERM signal!" - while true; do sleep 5; done -} -trap _term SIGTERM -while true; do sleep 5; done -`}, + sleep 9999999 & + PID=$! + _term() { + echo "Caught SIGTERM signal!" + wait $PID + } + + trap _term SIGTERM + wait $PID + `}, }, }, TerminationGracePeriodSeconds: &gracePeriod,