Skip to content

Commit 0bb640c

Browse files
authored
Merge pull request kubernetes#92205 from mrunalp/fix_host_path_socket_tests
test: Start a pod with nc instead of execing a background command
2 parents 6bb668c + 7643b64 commit 0bb640c

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

test/e2e/storage/host_path_type.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,9 @@ var _ = utils.SIGDescribe("HostPathType Socket [Slow]", func() {
193193
ginkgo.By("Create a pod for further testing")
194194
hostBaseDir = path.Join("/tmp", ns)
195195
mountBaseDir = "/mnt/test"
196-
basePod = f.PodClient().CreateSync(newHostPathTypeTestPod(map[string]string{}, hostBaseDir, mountBaseDir, &hostPathDirectoryOrCreate))
196+
basePod = f.PodClient().CreateSync(newHostPathTypeTestPodWithCommand(map[string]string{}, hostBaseDir, mountBaseDir, &hostPathDirectoryOrCreate, fmt.Sprintf("nc -lU %s", path.Join(mountBaseDir, "asocket"))))
197197
ginkgo.By(fmt.Sprintf("running on node %s", basePod.Spec.NodeName))
198198
targetSocket = path.Join(hostBaseDir, "asocket")
199-
ginkgo.By("Create a socket for further testing")
200-
_, err := utils.PodExec(f, basePod, fmt.Sprintf("nc -lU %s &", path.Join(mountBaseDir, "asocket")))
201-
framework.ExpectNoError(err)
202199
})
203200

204201
ginkgo.It("Should fail on mounting non-existent socket 'does-not-exist-socket' when HostPathType is HostPathSocket", func() {
@@ -409,6 +406,45 @@ func newHostPathTypeTestPod(nodeSelector map[string]string, hostDir, mountDir st
409406
return pod
410407
}
411408

409+
func newHostPathTypeTestPodWithCommand(nodeSelector map[string]string, hostDir, mountDir string, hostPathType *v1.HostPathType, command string) *v1.Pod {
410+
pod := &v1.Pod{
411+
ObjectMeta: metav1.ObjectMeta{
412+
GenerateName: "test-hostpath-type-",
413+
},
414+
Spec: v1.PodSpec{
415+
NodeSelector: nodeSelector,
416+
RestartPolicy: v1.RestartPolicyNever,
417+
Containers: []v1.Container{
418+
{
419+
Name: "host-path-sh-testing",
420+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
421+
VolumeMounts: []v1.VolumeMount{
422+
{
423+
Name: "host",
424+
MountPath: mountDir,
425+
ReadOnly: false,
426+
},
427+
},
428+
Command: []string{"sh"},
429+
Args: []string{"-c", command},
430+
},
431+
},
432+
Volumes: []v1.Volume{
433+
{
434+
Name: "host",
435+
VolumeSource: v1.VolumeSource{
436+
HostPath: &v1.HostPathVolumeSource{
437+
Path: hostDir,
438+
Type: hostPathType,
439+
},
440+
},
441+
},
442+
},
443+
},
444+
}
445+
return pod
446+
}
447+
412448
func verifyPodHostPathTypeFailure(f *framework.Framework, nodeSelector map[string]string, hostDir, pattern string, hostPathType *v1.HostPathType) {
413449
pod := newHostPathTypeTestPod(nodeSelector, hostDir, "/mnt/test", hostPathType)
414450
ginkgo.By(fmt.Sprintf("Creating pod %s", pod.Name))

0 commit comments

Comments
 (0)