Skip to content

Commit 58e15c8

Browse files
authored
Merge pull request kubernetes#125431 from huww98/e2e-term-sleep
e2e: add TERM trap to pod sleep command
2 parents 0aab2a3 + 859bd02 commit 58e15c8

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

test/e2e/common/storage/empty_dir.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ var _ = SIGDescribe("EmptyDir volumes", func() {
259259
Name: busyBoxMainContainerName,
260260
Image: imageutils.GetE2EImage(imageutils.BusyBox),
261261
Command: []string{"/bin/sh"},
262-
Args: []string{"-c", "sleep 100000"},
262+
Args: []string{"-c", e2epod.InfiniteSleepCommand},
263263
VolumeMounts: []v1.VolumeMount{
264264
{
265265
Name: volumeName,
@@ -330,7 +330,7 @@ var _ = SIGDescribe("EmptyDir volumes", func() {
330330
Name: busyBoxMainContainerName,
331331
Image: imageutils.GetE2EImage(imageutils.BusyBox),
332332
Command: []string{"/bin/sh"},
333-
Args: []string{"-c", "sleep 100000"},
333+
Args: []string{"-c", e2epod.InfiniteSleepCommand},
334334
VolumeMounts: []v1.VolumeMount{
335335
{
336336
Name: volumeName,

test/e2e/framework/deployment/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (o replicaSetsByCreationTimestamp) Less(i, j int) bool {
178178
// name. A slice of BASH commands can be supplied as args to be run by the pod
179179
func testDeployment(replicas int32, podLabels map[string]string, nodeSelector map[string]string, namespace string, pvclaims []*v1.PersistentVolumeClaim, securityLevel admissionapi.Level, command string) *appsv1.Deployment {
180180
if len(command) == 0 {
181-
command = "trap exit TERM; while true; do sleep 1; done"
181+
command = e2epod.InfiniteSleepCommand
182182
}
183183
zero := int64(0)
184184
deploymentName := "deployment-" + string(uuid.NewUUID())

test/e2e/framework/pod/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func CreateSecPodWithNodeSelection(ctx context.Context, client clientset.Interfa
131131
// name. A slice of BASH commands can be supplied as args to be run by the pod
132132
func MakePod(ns string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim, securityLevel admissionapi.Level, command string) *v1.Pod {
133133
if len(command) == 0 {
134-
command = "trap exit TERM; while true; do sleep 1; done"
134+
command = InfiniteSleepCommand
135135
}
136136
podSpec := &v1.Pod{
137137
TypeMeta: metav1.TypeMeta{
@@ -172,7 +172,7 @@ func MakeSecPod(podConfig *Config) (*v1.Pod, error) {
172172
return nil, fmt.Errorf("Cannot create pod with empty namespace")
173173
}
174174
if len(podConfig.Command) == 0 {
175-
podConfig.Command = "trap exit TERM; while true; do sleep 1; done"
175+
podConfig.Command = InfiniteSleepCommand
176176
}
177177

178178
podName := "pod-" + string(uuid.NewUUID())

test/e2e/framework/pod/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func NodeOSDistroIs(distro string) bool {
4343
return false
4444
}
4545

46+
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
47+
4648
// GenerateScriptCmd generates the corresponding command lines to execute a command.
4749
func GenerateScriptCmd(command string) []string {
48-
var commands []string
49-
commands = []string{"/bin/sh", "-c", command}
50-
return commands
50+
return []string{"/bin/sh", "-c", command}
5151
}
5252

5353
// GetDefaultTestImage returns the default test image based on OS.

test/e2e/node/pod_resize.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ func initDefaultResizePolicy(containers []TestContainerInfo) {
174174
}
175175

176176
func makeTestContainer(tcInfo TestContainerInfo) (v1.Container, v1.ContainerStatus) {
177-
cmd := "trap exit TERM; while true; do sleep 1; done"
178177
res, alloc, resizePol := getTestResourceInfo(tcInfo)
179178
bTrue := true
180179
bFalse := false
@@ -209,7 +208,7 @@ func makeTestContainer(tcInfo TestContainerInfo) (v1.Container, v1.ContainerStat
209208
Name: tcInfo.Name,
210209
Image: imageutils.GetE2EImage(imageutils.BusyBox),
211210
Command: []string{"/bin/sh"},
212-
Args: []string{"-c", cmd},
211+
Args: []string{"-c", e2epod.InfiniteSleepCommand},
213212
Resources: res,
214213
ResizePolicy: resizePol,
215214
SecurityContext: securityContext,

test/e2e/storage/testsuites/ephemeral.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (p *ephemeralTestSuite) DefineTests(driver storageframework.TestDriver, pat
295295

296296
l.testCase.RunningPodCheck = func(ctx context.Context, pod *v1.Pod) interface{} {
297297
// Create another pod with the same inline volume attributes.
298-
pod2 := StartInPodWithInlineVolume(ctx, f.ClientSet, f.Namespace.Name, "inline-volume-tester2", "sleep 100000",
298+
pod2 := StartInPodWithInlineVolume(ctx, f.ClientSet, f.Namespace.Name, "inline-volume-tester2", e2epod.InfiniteSleepCommand,
299299
[]v1.VolumeSource{pod.Spec.Volumes[0].VolumeSource},
300300
readOnly,
301301
l.testCase.Node)
@@ -387,7 +387,6 @@ func (t EphemeralTest) TestEphemeral(ctx context.Context) {
387387
gomega.Expect(client).NotTo(gomega.BeNil(), "EphemeralTest.Client is required")
388388

389389
ginkgo.By(fmt.Sprintf("checking the requested inline volume exists in the pod running on node %+v", t.Node))
390-
command := "sleep 10000"
391390

392391
var volumes []v1.VolumeSource
393392
numVolumes := t.NumInlineVolumes
@@ -415,7 +414,7 @@ func (t EphemeralTest) TestEphemeral(ctx context.Context) {
415414
}
416415
volumes = append(volumes, volume)
417416
}
418-
pod := StartInPodWithInlineVolume(ctx, client, t.Namespace, "inline-volume-tester", command, volumes, t.ReadOnly, t.Node)
417+
pod := StartInPodWithInlineVolume(ctx, client, t.Namespace, "inline-volume-tester", e2epod.InfiniteSleepCommand, volumes, t.ReadOnly, t.Node)
419418
defer func() {
420419
// pod might be nil now.
421420
StopPodAndDependents(ctx, client, t.Timeouts, pod)

test/e2e/storage/testsuites/subpath.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func (s *subPathTestSuite) DefineTests(driver storageframework.TestDriver, patte
449449

450450
// Change volume container to busybox so we can exec later
451451
l.pod.Spec.Containers[1].Image = e2epod.GetDefaultTestImage()
452-
l.pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd("sleep 100000")
452+
l.pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
453453
l.pod.Spec.Containers[1].Args = nil
454454

455455
ginkgo.By(fmt.Sprintf("Creating pod %s", l.pod.Name))
@@ -793,10 +793,10 @@ func testPodContainerRestartWithHooks(ctx context.Context, f *framework.Framewor
793793
pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure
794794

795795
pod.Spec.Containers[0].Image = e2epod.GetDefaultTestImage()
796-
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd("sleep 100000")
796+
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
797797
pod.Spec.Containers[0].Args = nil
798798
pod.Spec.Containers[1].Image = e2epod.GetDefaultTestImage()
799-
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd("sleep 100000")
799+
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
800800
pod.Spec.Containers[1].Args = nil
801801
hooks.AddLivenessProbe(pod, probeFilePath)
802802

@@ -971,10 +971,10 @@ func testSubpathReconstruction(ctx context.Context, f *framework.Framework, host
971971

972972
// Change to busybox
973973
pod.Spec.Containers[0].Image = e2epod.GetDefaultTestImage()
974-
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd("sleep 100000")
974+
pod.Spec.Containers[0].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
975975
pod.Spec.Containers[0].Args = nil
976976
pod.Spec.Containers[1].Image = e2epod.GetDefaultTestImage()
977-
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd("sleep 100000")
977+
pod.Spec.Containers[1].Command = e2epod.GenerateScriptCmd(e2epod.InfiniteSleepCommand)
978978
pod.Spec.Containers[1].Args = nil
979979
// If grace period is too short, then there is not enough time for the volume
980980
// manager to cleanup the volumes

test/e2e/storage/testsuites/volumelimits.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (t *volumeLimitsTestSuite) DefineTests(driver storageframework.TestDriver,
170170
// Create <limit> Pods.
171171
ginkgo.By(fmt.Sprintf("Creating %d Pod(s) with one volume each", limit))
172172
for i := 0; i < limit; i++ {
173-
pod := StartInPodWithVolumeSource(ctx, l.cs, *l.resource.VolSource, l.ns.Name, "volume-limits", "sleep 1000000", selection)
173+
pod := StartInPodWithVolumeSource(ctx, l.cs, *l.resource.VolSource, l.ns.Name, "volume-limits", e2epod.InfiniteSleepCommand, selection)
174174
l.podNames = append(l.podNames, pod.Name)
175175
l.pvcNames = append(l.pvcNames, ephemeral.VolumeClaimName(pod, &pod.Spec.Volumes[0]))
176176
}
@@ -214,7 +214,7 @@ func (t *volumeLimitsTestSuite) DefineTests(driver storageframework.TestDriver,
214214
}
215215

216216
ginkgo.By("Creating an extra pod with one volume to exceed the limit")
217-
pod := StartInPodWithVolumeSource(ctx, l.cs, *l.resource.VolSource, l.ns.Name, "volume-limits-exceeded", "sleep 10000", selection)
217+
pod := StartInPodWithVolumeSource(ctx, l.cs, *l.resource.VolSource, l.ns.Name, "volume-limits-exceeded", e2epod.InfiniteSleepCommand, selection)
218218
l.podNames = append(l.podNames, pod.Name)
219219

220220
ginkgo.By("Waiting for the pod to get unschedulable with the right message")

0 commit comments

Comments
 (0)