diff --git a/pkg/config/init.go b/pkg/config/init.go index 0ed680358..20c08a278 100644 --- a/pkg/config/init.go +++ b/pkg/config/init.go @@ -44,9 +44,9 @@ var BuildContextDir = fmt.Sprintf("%s/buildcontext/", KanikoDir) // as tarballs in case they are needed later on var KanikoIntermediateStagesDir = fmt.Sprintf("%s/stages/", KanikoDir) -var IgnoreListPath string +var MountInfoPath string func init() { RootDir = constants.RootDir - IgnoreListPath = constants.IgnoreListPath + MountInfoPath = constants.MountInfoPath } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 678a32fe2..9c544ebcd 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -20,7 +20,7 @@ const ( // RootDir is the path to the root directory RootDir = "/" - IgnoreListPath = "/proc/self/mountinfo" + MountInfoPath = "/proc/self/mountinfo" DefaultKanikoPath = "/kaniko" diff --git a/pkg/executor/copy_multistage_test.go b/pkg/executor/copy_multistage_test.go index 88e797e65..89cd044ec 100644 --- a/pkg/executor/copy_multistage_test.go +++ b/pkg/executor/copy_multistage_test.go @@ -176,9 +176,9 @@ func setupMultistageTests(t *testing.T) (string, func()) { if err := ioutil.WriteFile(mFile, []byte(mountInfo), 0644); err != nil { t.Fatal(err) } - config.IgnoreListPath = mFile + config.MountInfoPath = mFile return testDir, func() { config.RootDir = constants.RootDir - config.IgnoreListPath = constants.IgnoreListPath + config.MountInfoPath = constants.MountInfoPath } } diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 9bf50c907..f51e86444 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -1022,7 +1022,7 @@ func InitIgnoreList(detectFilesystem bool) error { ignorelist = append([]IgnoreListEntry{}, defaultIgnoreList...) if detectFilesystem { - if err := DetectFilesystemIgnoreList(config.IgnoreListPath); err != nil { + if err := DetectFilesystemIgnoreList(config.MountInfoPath); err != nil { return errors.Wrap(err, "checking filesystem mount paths for ignore list") } } diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index 108a42092..6f13e808a 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -1013,6 +1013,9 @@ func fakeExtract(dest string, hdr *tar.Header, tr io.Reader) error { } func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T) { + var resetMountInfoFile = provideEmptyMountinfoFile() + defer resetMountInfoFile() + ctrl := gomock.NewController(t) root := t.TempDir() @@ -1108,7 +1111,20 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T) } } +func provideEmptyMountinfoFile() func() { + // Provide empty mountinfo file to prevent /tmp from ending up in ignore list on + // distributions with /tmp mountpoint. Otherwise, tests expecting operations in /tmp + // can fail. + config.MountInfoPath = "/dev/null" + return func() { + config.MountInfoPath = constants.MountInfoPath + } +} + func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T) { + var resetMountInfoFile = provideEmptyMountinfoFile() + defer resetMountInfoFile() + ctrl := gomock.NewController(t) root := t.TempDir() @@ -1209,6 +1225,9 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T) } func Test_GetFSFromLayers_ignorelist(t *testing.T) { + var resetMountInfoFile = provideEmptyMountinfoFile() + defer resetMountInfoFile() + ctrl := gomock.NewController(t) root := t.TempDir() @@ -1452,9 +1471,9 @@ func TestInitIgnoreList(t *testing.T) { if _, err := mFile.WriteString(mountInfo); err != nil { t.Fatal(err) } - config.IgnoreListPath = mFile.Name() + config.MountInfoPath = mFile.Name() defer func() { - config.IgnoreListPath = constants.IgnoreListPath + config.MountInfoPath = constants.MountInfoPath }() expected := []IgnoreListEntry{