Move snapshotPathPrefix into a method

This allows the value to be determined on the fly, which supports consumers that use Kaniko snaphot as a library and may need to change the value of config.KanikoDir
This commit is contained in:
Joe Kutner
2020-07-26 21:46:33 -05:00
parent 0c71a1bb0e
commit 29a02b08ff
+9 -2
View File
@@ -33,7 +33,7 @@ import (
)
// For testing
var snapshotPathPrefix = config.KanikoDir
var snapshotPathPrefix = ""
// Snapshotter holds the root directory from which to take snapshots, and a list of snapshots taken
type Snapshotter struct {
@@ -119,7 +119,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string,
// TakeSnapshotFS takes a snapshot of the filesystem, avoiding directories in the ignorelist, and creates
// a tarball of the changed files.
func (s *Snapshotter) TakeSnapshotFS() (string, error) {
f, err := ioutil.TempFile(snapshotPathPrefix, "")
f, err := ioutil.TempFile(s.getSnashotPathPrefix(), "")
if err != nil {
return "", err
}
@@ -138,6 +138,13 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
return f.Name(), nil
}
func (s *Snapshotter) getSnashotPathPrefix() string {
if snapshotPathPrefix == "" {
return config.KanikoDir
}
return snapshotPathPrefix
}
func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) {
logrus.Info("Taking snapshot of full filesystem...")