From a5ce3b3cd7106133041521ac15025b491fdfdc43 Mon Sep 17 00:00:00 2001
From: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Date: Wed, 11 Jan 2023 13:41:30 +0900
Subject: [PATCH] e2e: fix play_kube_test

When SELinux is enabled, e2e test could be failed
due to run a ls command in a running container.

Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
---
 test/e2e/play_kube_test.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 336e3b47ef..dc4ad98e82 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -3157,12 +3157,18 @@ spec:
 		hostPathDir := filepath.Join(tempdir, testdir)
 		err := os.Mkdir(hostPathDir, 0755)
 		Expect(err).ToNot(HaveOccurred())
+		defer os.RemoveAll(hostPathDir)
 
 		hostPathDirFile := filepath.Join(hostPathDir, testfile)
 		f, err := os.Create(hostPathDirFile)
 		Expect(err).ToNot(HaveOccurred())
 		f.Close()
 
+		if selinux.GetEnabled() {
+			label := SystemExec("chcon", []string{"-t", "container_file_t", hostPathDirFile})
+			Expect(label).Should(Exit(0))
+		}
+
 		// Create container image with named volume
 		containerfile := fmt.Sprintf(`
 FROM  %s