Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fs_util tests failing on systems with /tmp mountpoint #2583

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
// RootDir is the path to the root directory
RootDir = "/"

IgnoreListPath = "/proc/self/mountinfo"
MountInfoPath = "/proc/self/mountinfo"

DefaultKanikoPath = "/kaniko"

Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/copy_multistage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
23 changes: 21 additions & 2 deletions pkg/util/fs_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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{
Expand Down