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
@@ -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...")
